Sample code for 30+ languages & platforms
JavaScript

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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
// Create JSON with members of different data types.
var json = new CkJsonObject();

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

json.EmitCompact = false;
console.log(json.Emit());

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

var a = json.StringOf("a");
console.log(a);

var b = json.StringOf("b");
console.log(b);

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