This program will take JSON and convert it to a multivalued record containing the field titles and field values. This sort of logging makes it easy to view json data from the Universe terminal.

# Implementation

CALL LOG.JSON(JSON, FILE, RECORD, ERRORS)

JSON - A String containing the JSON. You may need to quote the string using QUOTE(JSON).

FILE - The opened file that you want to write the record to.

RECORD - The name of the record to save.

ERRORS - Any errors that this sub produces will be stored here.

# Structure

The field titles are stored at the value level in field 1 of the record.

The field values are stored at the value level in field 2 of the record.

# Nested objects and arrays

The titles are stored in dot notation. For example

{
    "foo": "123",
    "customer": {
        "name": "Acme",
        "state": "CA"
    },
    "fruits": [
        {
            "name": "apple"
        },
        {
            "name": "banana"
        }
    ]
}

The customer's state would have a title of customer.state.

The banana would have a title of fruits.2.name.

WARNING

Nesting can only go 4 levels deep currently. This is because UDO handles can not be stored in dynamic arrays.

# Viewing

To view the record from the terminal, use something like:

LIST SOME.FILE SOME.RECORD F1 F2 ID.SUP

Just replace SOME.FILE and SOME.RECORD with your own values.

# Testing

Testing for this is at NRL.BP TEST.LOG.JSON.

It can be ran by doing the following:

MV.TEST NRL.BP TEST.LOG.JSON

Please refer to the MV TEST section to learn more about testing.