Sample code for 30+ languages & platforms
Chilkat2-Python

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 Chilkat2-Python Downloads

Chilkat2-Python
import chilkat2

# Create JSON with members of different data types.
json = chilkat2.JsonObject()

json.UpdateInt("a",123)
json.UpdateBool("b",True)
json.UpdateNull("c")

json.EmitCompact = False
print(json.Emit())

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

a = json.StringOf("a")
print(a)

b = json.StringOf("b")
print(b)

c = json.StringOf("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
ival = json.IntOf("a")
bval = json.BoolOf("b")
hasNull = json.IsNullOf("c")