Skip to content

JSON format structure

Paweł Waligóra edited this page Feb 15, 2025 · 3 revisions

Since version 2.2.0, apart from .format files you can specify output file format with JSON files

This article only outlines the structure of JSON files and does not explain how do they translate to compilation format. It is advised that you read format file syntax page first. JSON members are named exactly as key-words in .format file.

Structure

Whole file must be an object with only one array member named "units".

{
    "units": [

    ]
}

"units" must be an array of JSON objects of two allowed types:

  • file units
  • helper units

Units

Each unit can have a "preamble" and "buffers" members, which must be arrays.

{
    "preamble": [

    ],
    "buffers": [

    ]
}

Preamble is an array of fields and buffer is an array of buffers

What separates helper units from file units is that:

  • helper units must have a "name" string member - that can be referred to later
  • file units must have an "output_file" string member that defines output file name, uses same pattern file naming as in .format file

Additionally file untis may specify "print_mode" member, which may take on of following values:

  • plainText, plain-text, plain_text - specifies that output file will be in plain text
  • binary - specifies that output file will be binary (default)

Fields

field can be either a string or JSON object structure like one below:

{
    "value":
    "type":
}

fields written as strings are parsed exactly the same way as in .format file. In case of JSON objects "type" refers to part before : and "value" to part after.

Buffers

one buffer JSON object can contain to array members: "preamble" and "fields", both of which are arrays of fields.

{
    "preamble": [
        "uint4:buffs",
        {"type": "uint", "value": "fieldb"}
    ],
    "fields": [
        "float:vertex",
        {"type": "float4", "value": 2.56}
    ]
}

Example

{
    "units": [
        {
            "name": "mesh",
            "preamble": [
                "int4:-50",
                "uint4:buffu",
                "uint4:buffs",
                "uint4:entryu",
                "entryb",
                "entrys",
                "fieldu",
                "fieldb",
                "fielde",
                "fields"
            ],
            "buffers": [
                {
                    "preamble": [
                        "int4:-30",
                        "buffs",
                        "entryb",
                        "entrys",
                        "fieldb",
                        "fielde",
                        "uint4:fields"
                    ],
                    "fields": [
                        "float:vertex.x",
                        "vertex.y",
                        "vertex.z",
                        "int4:-20"
                    ]
                },
                {
                    "preamble": [
                        "int4:-30",
                        "buffs",
                        "entryb",
                        "entrys",
                        "fieldb",
                        "fielde",
                        "uint4:fields"
                    ],
                    "fields": [
                        "float:vertex.x",
                        "vertex.y",
                        "vertex.z",
                        "int4:-20"
                    ]
                }
            ]
        },
        {
            "output_file": "tests/acceptance/res/{mesh}_json_su.txt",
            "print_mode": "plainText",
            "preamble": [
                "mesh"
            ]
        }
    ]
}
Clone this wiki locally