Lua
Lua
JSON: Renaming and Deleting Members
See more JSON Examples
Demonstrates renaming and deleting members. This example uses the following JSON document:
{
"apple": "red",
"lime": "green",
"banana": "yellow",
"broccoli": "green",
"strawberry": "red"
}
Chilkat Lua Downloads
local chilkat = require("chilkat")
local json = chilkat.JsonObject.new()
local success = json:load("{\"apple\": \"red\",\"lime\": \"green\",\"banana\": \"yellow\",\"broccoli\": \"green\",\"strawberry\": \"red\"}")
if not success then
print(json.last_error_text)
return
end
-- Rename "lime" to "lemon".
success = json:rename("lime", "lemon")
-- Change the color to yellow:
success = json:set_string_of("lemon", "yellow")
-- Rename by index. Banana is at index 2 (apple is at index 0)
success = json:rename_at(2, "bartlett_pear")
-- Delete broccoli by name
success = json:delete("broccoli")
-- Delete apple by index. Apple is at index 0.
success = json:delete_at(0)
json.emit_compact = false
print(json:emit())