6.6. JSON Configuration File Format

This reference describes the format of JSON configuration files for programs that create or change them, such as generator scripts and AI coding assistants. Such programs prefer this format over Python configuration files; see Choosing between JSON and Python.

To create or change a configuration yourself, use the graphical configuration interface axivion_config instead of editing JSON configuration files in a text editor. axivion_config uses this format, sets the version entries, and validates every value while you edit it.

6.6.1. File structure

A JSON configuration file is a JSON object with one entry per configuration aspect and the version entries _Format and _VersionNum. The aspects are Analysis, Project, Results, and Tools. Each aspect entry maps rule and rule group names to objects that hold the settings for that rule or group.

All rule and rule group entries are immediate children of the aspect object, regardless of their place in the rule group hierarchy. The settings for the rule /Analysis/Stylechecks/Misra/MisraC2012/MisraC2012-10/MisraC2012-10.3 are stored as the value of the key MisraC2012-10.3 inside Analysis. They are not nested inside the objects Stylechecks, Misra, MisraC2012, and MisraC2012-10. This flat structure works because the names of all rules and rule groups inside an aspect are unique.

A file only lists the rules and options that it changes. All other settings are inherited from the more global layers and the defaults. Interface layers have a different structure; see Configuration Files.

A JSON configuration file
{
    ".#": "Rule selection for the example project",
    "Analysis": {
        "Analysis-GlobalOptions": {
            "types": {
                "allow_single_bitfield_as_bool": true
            }
        },
        "MisraC2012-1.1": {
            "_active": true
        },
        "MisraC2012-10.3": {
            "_active": true,
            "severity": "error",
            "excludes": {
                "$(delta:+)": ["*/thirdparty/*"],
                "$(delta:-)": ["*/test/*"]
            }
        },
        "MyRule-1": {
            "_copy_from": "MisraC2012-10.3",
            "_active": true,
            "severity.#": "MyCompany rates this lower than MISRA",
            "severity": "note"
        }
    },
    "_Format": "1.0",
    "_VersionNum": [7, 13, 0, 21548]
}

6.6.2. Version entries

_VersionNum holds the version of the Axivion Suite that wrote the file as a list of four integers. Configuration files from older versions are migrated using this entry when they are loaded. Without it, they cannot be migrated. _Format holds the version of the file format, currently "1.0".

Obtain both entries from the installed Axivion Suite. If BAUHAUS_CONFIG is unset, the following axivion_config_tool command prints an empty configuration file with the current entries. An empty --config value falls back to BAUHAUS_CONFIG.

axivion_config_tool delta --json_only --config ""

6.6.3. Activating rules

The pseudo option _active activates (true) or deactivates (false) a rule or a rule group. Activating a rule group activates all rules in it. Rules in an ordered rule group such as Architecture run in the order of the group’s child_order option, which is a list of rule names.

Activating rules in JSON
{
    "Analysis": {
        "MisraC2012-1.1": { "_active": true },
        "Architecture-ArchitectureCheck": { "_active": true },
        "MisraC2012-10.3": { "_active": true, "severity": "error" }
    }
}

6.6.4. Setting options

Rule options are set using their names inside the rule’s object. The available options and their types are listed in the rule reference. Options with a structured type are written as nested JSON objects that list only the fields to change. Global options of an aspect are set in the pseudo rule <aspect>-GlobalOptions, e.g., Analysis-GlobalOptions. Option values may contain variable substitutions.

Setting a rule option and a global option in JSON
{
    "Analysis": {
        "Analysis-GlobalOptions": {
            "types": {
                "allow_single_bitfield_as_bool": true
            }
        },
        "MisraC2012-10.3": { "severity": "error" }
    }
}

The pseudo option _additional_rules of Analysis-GlobalOptions lists directories with additional rules. Relative paths are interpreted relative to the configuration file.

Using additional rules in JSON
{
    "Analysis": {
        "Analysis-GlobalOptions": {
            "_additional_rules": ["some/where"]
        },
        "MyOwnRule": { "_active": true }
    }
}

6.6.5. Copying rules

An entry with the pseudo option _copy_from creates a copy of the named rule or rule group under the entry’s name. The copy starts with the settings of the original rule at the point where the file is loaded, and the remaining options of the entry are applied to the copy. The source must be an existing rule, not a copy created in the same file. Moving a rule into a different rule group cannot be done via JSON; see Python API.

Copying a rule in JSON
{
    "Analysis": {
        "MisraC2012-10.3": { "_active": true },
        "MyRule-1": {
            "_copy_from": "MisraC2012-10.3",
            "_active": true,
            "severity": "note",
            "provider": "MyCompany"
        }
    }
}

6.6.6. Changing sets, lists and dictionaries

A plain JSON value replaces the inherited value of an option. To change a set, list, or dictionary relative to the inherited value, write a delta object with the keys $(delta:-) and $(delta:+). $(delta:-) is a list of the elements or dictionary keys to remove. $(delta:+) is a list of the elements to add, or an object of the dictionary entries to add or replace. Elements are removed first. New list elements are appended at the end. See Delta editing for the effect on subsequent changes to the inherited value.

6.6.7. Comments

Keys ending in .# are comments and are ignored, whether at the top level or in an aspect object, a rule object, or the object of a structured option. The convention is to name a comment after the entry it describes, e.g., "severity.#" for a comment on "severity". A comment on the activation state of a rule is named "_active.#". axivion_config shows and edits comments written this way; see Comments.

6.6.8. Keeping files minimal

List only the rules and options whose value differs from the more global layers and the defaults. The following command prints the settings that new.json changes on top of the configuration base.json, with the layers in BAUHAUS_CONFIG notation. Entries of new.json that are missing from the output repeat an inherited value and can be removed. The command only covers active rules.

axivion_config_tool delta --json_only --config new.json:base.json base.json

6.6.9. Checking a configuration file

Check every written file with axivion_analysis --validate; see Validating and Converting Configurations.