JSON Format for Input/Output

Purpose

The JSON object notation format was chosen because numerous reader are available, and it’s also human-readable. The structure has its focus on values, rather any descriptive elements, as it is the same with binary BUFR.

Decode BUFR to JSON Output

To decode a BUFR into a JSON object, either use the instance method Bufr.decode() or the command-line parameter -j | --decode-json.

Encode JSON Input to BUFR

To encode a file with a JSON object into binary BUFR, either use the instance method Bufr.encode() or the command-line parameter -e | --encode.

JSON Structure

The content of an input and output file as formatted following the JSON structure consist of one list [...] as top-level element.

Each entry in this list represents one BUFR message.

One BUFR message is build as a dictionary {...} with following keys:

  • “index” : integer value, equal to the list index of this BUFR in the top-level list.

  • “file” : optional, set if the command-line scripts are used for decoding and encoding:

    • Original file name, if a file was decoded.
    • File name used for encoding.
  • “heading” : optional,

    • Set if the decoded file contained a WMO bulletin.
    • Used as WMO abbreviated heading line for a WMO bulletin on encoding.
  • “bufr” : the value representation of the BUFR.

Example:

[{
    "index": 0,
    "bufr": [ ... ],
    "heading": null,
    "file": "207003.bufr"
}]

The value representation of one BUFR is one list [...], its elements are the BUFR sections 0 to 4, where each is a list of values.

Length identifyer

In contrast to the binary BUFR, there are NO length values denoting either the length of a section, or the ammount of repetition. On encoding they will be calculated, thus making the handling of delayed replication easier.

Booleans, None, Strings, and Numbers

With JSON, boolean values are encoded as true or false, which is the case for some flag-values in sections 1 and 3.

In the data section 4, for any missing value the keyword none is set in the JSON structure.

Strings, or character sequences, are stored as sequences of ITA-5 (which is equivalent to US-ASCII) characters, surrounded with double-quotes ". When encoding a JSON object as BUFR, the underlying functions take care of padding/truncating the strings to match the width as defined by the descriptor.

Numbers are … numbers. Either integer or decimal-point values.

Section 0 – Indicator section

Always has exactly two elements:

  • the keyword "BUFR".
  • the BUFR edition number.
["BUFR", 3],

Section 1 – Identification section

The identification elements, or meta-data, of this BUFR.

The elements meaning follows the same order as encoded in BUFR according to the BUFR edition.

Although the representative time is encoded in BUFR Ed.3 without a value for the seconds, they are always set in the JSON structure – in which case they are set to zero. On encoding a JSON structure into BUFR Ed.3, the value for seconds will be ignored.

[0, 0, 98, 0, false, 21, 202, 15, 0, 2012, 11, 2, 0, 0, 0],

Section 2 – Optional section (local data)

This section is optional in encoding a BUFR, but the corresponding list entry is required.

Empty section:

[],

If the local data section 2 should not be present in the BUFR when encoding or decoding, the list representing the values of this section shall be left empty.

Section with values:

["03", "59", "7d", "ca", "7d", "20", "00", "53", "10", "94"],

If data for local application use either was encoded in the BUFR or should be used when encoding a BUFR, the numerical ASCII values of all bytes shall be listed, each wrapped with double-quotes to set string values.

Section 3 – Data description section

Values listed in the following order:

  • Number of data subsets.
  • Data category flag.
  • Data compression flag.
  • Collection of descriptors which define the form and content of individual data elements.
[2, true, true, ["310060"]],

Section 5 – End section

Always has exactly one element: the keyword "7777".

["7777"]

Full Example

[{
    "index": 0,
    "bufr": [
        ["BUFR", 3],
        [0, 0, 98, 0, false, 21, 202, 15, 0, 2012, 11, 2, 0, 0, 0],
        [],
        [2, true, true, ["310060"]],
        [
            [224, 160, 620, 3, 2012, 11, 2, 0, 0, 27.584, 6675220.0, 2628450.5, 696570.75, 4.96669, 24.54144, 25.41, 282.91, 150.05, 111.28, 1, 1, 9, 7, 5258, 597, 829880.0, 1.0, 0, null, null, 2048, 0, [
                [2, 65000.0, 109500.0, 1, 713, 0, 1024],
                [3, 121000.0, 175000.0, 714, 1146, 0, 1024],
                [4, 215500.0, 255000.0, 1147, 1305, 0, 1024]
            ], null, 0, 0, [
                [1, 0.0462895],
                [2, 0.0454931],
                [3, 0.0421172],
                [4, 0.0453741],
                [5, 0.0431189]
            ]],
            [224, 160, 620, 3, 2012, 11, 2, 0, 0, 27.584, 6675220.0, 2628450.5, 696570.75, 5.05004, 24.3926, 24.2, 281.97, 150.22, 111.22, 1, 1, 9, 8, 5258, 538, 829880.0, 1.0, 0, null, null, 2048, 0, [
                [2, 65000.0, 109500.0, 1, 713, 0, 1024],
                [3, 121000.0, 175000.0, 714, 1146, 0, 1024],
                [4, 215500.0, 255000.0, 1147, 1305, 0, 1024]
            ], null, 0, 0, [
                [1, 0.0469285],
                [2, 0.0458891],
                [3, 0.041389],
                [4, 0.0447059],
                [5, 0.0430633]
            ]]
        ],
        ["7777"]
    ],
    "heading": null,
    "file": "207003.bufr"
}]