Search code examples
jsonjsonata

I need this json data in the below format using JSONATA


Below json is my input.

{
    "payload": {
        "KA01B3432": "KA01B3432",
        "KA02A3123": "KA02A3123"
    }
}

Using JSONATA i need to format the above JSON to below format.

[
    {
        "KA01B3432": "KA01B3432"
    },
    {
        "KA02A3123": "KA02A3123"
    }
]

I tried payload.[$keys()] but this will yield only keys in array format not whole object in array format.

{
    "payload": {
        "KA01B3432": "KA01B3432",
        "KA02A3123": "KA02A3123"
    }
}

to

[
    {
        "KA01B3432": "KA01B3432"
    },
    {
        "KA02A3123": "KA02A3123"
    }
]

Solution

  • $spread(payload) does what you need.

    See http://try.jsonata.org/S1COdDqO4