Sample code for 30+ languages & platforms
Node.js

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 Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    //  Create JSON with members of different data types.
    var json = new chilkat.JsonObject();

    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");

}

chilkatExample();