Valid JSON doesn't generate any bundles in Parse JSON

Why does this perfectly valid JSON, when put into a Parse JSON module generate 0 bundles. It runs without error but doesn’t generate anything:

[
    "item1",
    "item2",
    [
        "itemsub1",
        "itemsub2",
        [
            "itemsub3-sub1",
            "itemsub3-sub2"
        ],
        {
            "itemsub3-coll1": "value1",
            "itemsub3-coll2": "value2"
        }
    ]
]
1 Like

Just a thought, but not sure. It is because the array itself is not defined? The JSON is syntactically correct, but maybe Make needs context before it can parse it.

This doesn’t generate anything either:

[
    "item1",
    "item2"
]

But if we place the JSON in a defined array, this works:

{
    "items": [
        "item1",
        "item2",
        [
            "itemsub1",
            "itemsub2",
            [
                "itemsub3-sub1",
                "itemsub3-sub2"
            ],
            {
                "itemsub3-coll1": "value1",
                "itemsub3-coll2": "value2"
            }
        ]
    ]
}

Cheers,
Henk

2 Likes

This is because the top level array has a mix of primitive and non-primitive data types.

For the top level array to output three bundles, it needs to only contain three objects (collections).

For the top level array to output a single bundle containing an array with three items, it needs to be wrapped in a collection with a named key.

In your case there is no collection in your top level array AND you are mixing up data types.

samliewrequest private consultation

Join the unofficial Make Discord server to chat with us!

1 Like

@samliew and @Henk-Operative thanks for this – indeed the array needs to be in a collection with a named key (eg “items” like you put @Henk-Operative) for it to be parsed properly. I wish Parse JSON would throw a flag of some sort rather than returning nothing though.

2 Likes

For what it’s worth:

It’s worth considering this line of thinking: “a bundle output from any module in Make is a collection”. Parse JSON properly parsed your JSON, but didn’t find any top level collections – so no bundles.

As Samliew noted, this means you can also use Parse JSON to spit out multliple bundles (basically iterate) like this:

[ 
  {"data":1},
  {"data":2}
]
4 Likes