Sample code for 30+ languages & platforms
Lua

Using JSON StringOf with Non-String Members

See more JSON Examples

If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Create JSON with members of different data types.
local json = chilkat.JsonObject.new()

json:update_int("a", 123)
json:update_bool("b", true)
json:update_null("c")

json.emit_compact = false
print(json:emit())

-- Resulting JSON:
-- {
--   "a": 123,
--   "b": true,
--   "c": null
-- }

local a = json:string_of("a")
print(a)

local b = json:string_of("b")
print(b)

local c = json:string_of("c")
print(c)

-- Output

-- 123
-- true
-- null

-- If you want to get the integer, boolean, or null value
-- you need to use the methods matching the data type
local ival = json:int_of("a")
local bval = json:bool_of("b")
local hasNull = json:is_null_of("c")