Sample code for 30+ languages & platforms
Lua

JSON PathPrefix Example

Demonstrates the JSON object's PathPrefix property.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local success = false

local json = chilkat.JsonObject.new()

json.path_prefix = "company.billing."

json:update_string("company_name", "TechNova Solutions Inc.")
json:update_string("address_line_1", "123 Innovation Drive")
json:update_string("address_line_2", "Suite 450")
json:update_string("city", "Seattle")
json:update_string("state_province", "WA")
json:update_string("postal_code", "98101")
json:update_string("country", "USA")

json.emit_compact = false

print(json:emit())

-- Result:

-- {
--   "company": {
--     "billing": {
--       "company_name": "TechNova Solutions Inc.",
--       "address_line_1": "123 Innovation Drive",
--       "address_line_2": "Suite 450",
--       "city": "Seattle",
--       "state_province": "WA",
--       "postal_code": "98101",
--       "country": "USA"
--     }
--   }
-- }

local city = json:string_of("city")
print("city = " .. city)