JSON overriding#

JSON overriding is a concept widely used in the shapescape_custom_blocks_generator filter. It allows you to merge multiple JSON objects into one.

Examples#

Following examples show how the JSON overriding works, the A object in all of the examples is always the object that is being overridden. That means that “the B object is placed on top of the A object”.

Example 1 - Primitive properties#

A:

{
    "a": 1,
    "b": 2,
    "c": 3
}

B:

{
    "a": "a",
    "b": "b"
}

Result:

{
    "a": "a",
    "b": "b",
    "c": 3
}

Example 2 - Lists#

A:

{
    "a": [1, 2, 3],
    "b": [4, 5, 6]
}

B:

{
    "a": ["a", "b", "c"],
    "b": ["a", "b"]
}

Result:

{
    "a": ["a", "b", "c"],
    "b": ["a", "b", 6]
}

Example 3 - nested objects#

A:

{
    "a": {
        "a": 1,
        "b": 2
    },
    "b": {
        "a": 3,
        "b": 4
    }
}

B:

{
    "a": {
        "a": "a"
    },
    "b": "b"
}

Result:

{
    "a": {
        "a": "a",
        "b": 2
    },
    "b": "b"
}