jsontransformationjsonata

Jsonata Transformation to extract a value and make it a key


Jsonata newbie here. I need help with Jsonata Transformation to extract a value from json element and make it as key .

{

"key-1":[{

"id":"a",

"value":2.3

},{

"id":"b",

"value":2.3

}],

"key-2":[{
"id":"c",

"value":2.4

},{
"id":"d",

"value":2.5
}]

}

I want it to transform to "id" as key object as shown below

{
    "a": {
        "value": 2.3
    },
    "b": {
        "value": 2.3
    },
    "c": {
        "value": 2.4
    },
    "d": {
        "value": 2.5
    }
}

Solution

  • The following expression will do this:

    *{id: {'value': value}}

    See https://try.jsonata.org/BVQvBeMU9