Objects

Figure 19. ObjectConstructor

ObjectConstructor

Figure 20. 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 26. Empty object constructors

{}
      

Result: { }


Example 27. Object constructors 1

{ "foo" : "bar" }
      

Result: { "foo" : "bar" }


Example 28. Object constructors 2

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

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


Example 29. Object constructors 3

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

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


Example 30. Nested object constructors

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

Result: { "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 31. Object constructors with unquoted key 1

{ foo : "bar" }
      

Result: { "foo" : "bar" }


Example 32. Object constructors with unquoted key 2

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

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


Example 33. Object constructors with unquoted key 3

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

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


Example 34. Object constructors with needed quotes around the key

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

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