Object constructors

Figure 16. ObjectConstructor

ObjectConstructor

Figure 17. PairConstructor

PairConstructor

The syntax for creating objects is identical to that of JSON. You can use for an object key any string literal, and for an object value any literal, object constructor or array constructor.

Example 18. Empty object constructors

{}
      

Result (run with Zorba): { }


Example 19. Object constructors 1

{ "foo" : "bar" }
      

Result (run with Zorba): { "foo" : "bar" }


Example 20. Object constructors 2

{ "foo" : [ 1, 2, 3, 4, 5, 6 ] }
      

Result (run with Zorba): { "foo" : [ 1, 2, 3, 4, 5, 6 ] }


Example 21. Object constructors 3

{ "foo" : true, "bar" : false }
      

Result (run with Zorba): { "foo" : true, "bar" : false }


Example 22. Nested object constructors

{ "this is a key" : { "value" : "a value" } }
      

Result (run with Zorba): { "this is a key" : { "value" : "a value" } }


Oh, and like in JavaScript, if your key is simple enough (like alphanumerics, underscores, dashes, this kind of things), you are welcome to omit the quotes. The strings for which quotes are not mandatory are called NCNames. This class of strings can be used for unquoted keys, for variable and function names, and for module aliases.

Example 23. Object constructors with unquoted key 1

{ foo : "bar" }
      

Result (run with Zorba): { "foo" : "bar" }


Example 24. Object constructors with unquoted key 2

{ foo : [ 1, 2, 3, 4, 5, 6 ] }
      

Result (run with Zorba): { "foo" : [ 1, 2, 3, 4, 5, 6 ] }


Example 25. Object constructors with unquoted key 3

{ foo : "bar", bar : "foo" }
      

Result (run with Zorba): { "foo" : "bar", "bar" : "foo" }


Example 26. Object constructors with needed quotes around the key

{ "but you need the quotes here" : null }
    

Result (run with Zorba): { "but you need the quotes here" : null }