TOC Prev Next

JSON Sugar and other Goodness

Commas are Optional after Fields

Commas are optional at the end of fields. This is also true for the last field. The convention is to omit them.

CUE borrows a trick from Go to achieve this: the formal grammar still requires commas, but the scanner inserts commas according to a small set of simple rules.

commas.cue:

{
    one: 1
    two: 2

    "two-and-a-half": 2.5
}

$ cue export commas.cue

{
    "one": 1,
    "two": 2,
    "two-and-a-half": 2.5
}