generateJson

generateJson(source: Any;
             format: Integer): String;

The generateJson method of the JadeJson class generates JSON from a primitive type variable or an object.

The source parameter specifies the primitive type variable or object to be generated as JSON text output. The format parameter specifies the format type to generate (that is, Format_Json_Microsoft or Format_Json_Newton).

The return value is the generated JSON string.

Calling this method generates the JSON text for the source type in Microsoft or NewtonSoft format. These formats are different and not compatible in some cases.

If the source parameter is a primitive type, the returned text is the JSON textual version of that primitive type data; for example:

String: a string   Json ="a string"
Date: 23 November 2015   Json= "\/Date(1448236800000)\/"

For an object, the JSON output contains a textual description of the source object and the entire tree of objects referenced.

The format type represented by the Format_Json_Microsoft class constant rejects an object where an object is referenced more than once in the object tree (Microsoft JSON handling does not handle that situation).

The format type represented by the Format_Json_Newton class constant assigns a unique tag to each object, allowing multiple and circular references to be handled so that each object is included once only and subsequent references use the assigned tag for identification.

The following is a Microsoft example.

{"__type":"Customer","name":"smith","sex":"M","description":"","ignore":false,"image":[]}

The following is a NewtonSoft example that shows a type tag and an object identifier.

{"$type":"Customer","$id":"Customer4294967297","name":"Smith","bin":[],"description":"","ignore":false,"image":[]}

The JSON for the description of each object includes the type of the object in the text.