Lua Requires Chilkat v11.4.0+
Lua
Example: JsonObject.NewObjectOf method
Demonstrates theNewObjectOf method.
Chilkat Lua Downloads
local chilkat = require("chilkat")
local car = "{\"make\":\"Toyota\",\"model\":\"Camry\",\"year\":2022,\"color\":\"silver\",\"engine\":{\"type\":\"inline-4\",\"fuel\":\"gasoline\",\"horsepower\":203},\"features\":[\"bluetooth\",\"backup camera\",\"adaptive cruise control\",\"lane assist\"],\"isElectric\":false}"
local json = chilkat.JsonObject.new()
json:update_string("test", "abc")
local success = json:new_object_of("car", car)
if not success then
print(json.last_error_text)
return
end
json.emit_compact = false
print(json:emit())
-- Result:
-- {
-- "test": "abc",
-- "car": {
-- "make": "Toyota",
-- "model": "Camry",
-- "year": 2022,
-- "color": "silver",
-- "engine": {
-- "type": "inline-4",
-- "fuel": "gasoline",
-- "horsepower": 203
-- },
-- "features": [
-- "bluetooth",
-- "backup camera",
-- "adaptive cruise control",
-- "lane assist"
-- ],
-- "isElectric": false
-- }
-- }