Object (Json function)

From m204wiki
Jump to navigation Jump to search

Create an Object JSON object (Json class)

[Introduced in Model 204 7.6]

This function creates a Json object with an underlying type of object.

Summary

A Json object is a collection of pairs of (unicode) names and Json objects (null, number, string, boolean, array, or object). In serialized JSON, an object is represented as curly braces containing pairs of quoted names followed by colon followed by the value. The pairs are separated from each other with commas.

The following is a sample Json serialization of an object:

{"Name":"sprocket","Cost":23.18,"Source":null,"Sizes":["Small","Medium","Large"]}

Syntax

%json = [%(Json):]Object

Syntax terms

%jsonJson object
[%(Json):] The optional class name in parentheses denotes a virtual constructor.

Usage notes

  • As with all virtual or true constructors, it is usually not necessary to specify the %(json): before the Object method. That is %json = %(json):object is equivalent to %json = object.
  • Unlike Json arrays it is not possible to specify names and values on the Object virtual constructor. Instead, the must be added to the object with the Add or Item methods.

Examples

The following example populates an object with the values shown above:

b %json is object json %i is float %total is float %json = object %json('Name') = 'sprocket' %json('Cost') = 23.18 %json('Source') = null %json('Sizes') = array("Small", "Medium", "Large") printText {~=%json} end

This prints:

%json={"Name":"sprocket","Cost":23.18,"Source":null,"Sizes":["Small","Medium","Large"]}

See also