Search code examples
jsonata

How to map object values in JSONata


I have an object like:

{ "contact": { "value": 0 },
  "temperature": { "value": 5} 
}

That I would like converted to

{ "contact": 0,
  "temperature": 5
}

And I would like to avoid a spread/map/merge


Solution

  • I believe this is what you're looking for:

    $keys($){
      $: $lookup($$, $).value
    }
    

    You can check out this expression in Stedi's JSONata Playground here: https://stedi.link/V67vnsh