Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

# Create JSON with members of different data types.
set json [new_CkJsonObject]

CkJsonObject_UpdateInt $json "a" 123
CkJsonObject_UpdateBool $json "b" 1
CkJsonObject_UpdateNull $json "c"

CkJsonObject_put_EmitCompact $json 0
puts [CkJsonObject_emit $json]

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

set a [CkJsonObject_stringOf $json "a"]
puts "$a"

set b [CkJsonObject_stringOf $json "b"]
puts "$b"

set c [CkJsonObject_stringOf $json "c"]
puts "$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
set ival [CkJsonObject_IntOf $json "a"]
set bval [CkJsonObject_BoolOf $json "b"]
set hasNull [CkJsonObject_IsNullOf $json "c"]

delete_CkJsonObject $json