Using the example on the jmesPath home page, given this JSON:
{
"locations": [
{"name": "Seattle", "state": "WA"},
{"name": "New York", "state": "NY"},
{"name": "Bellevue", "state": "WA"},
{"name": "Olympia", "state": "WA"}
]
}
I want to transform select values in the JSON, and otherwise return the JSON intact. For example, suppose I wanted to move the city of New York to the state of Hawaii, and move Seattle to New Mexico. The result would be:
{
"locations": [
{"name": "Seattle", "state": "NM"},
{"name": "New York", "state": "HI"},
{"name": "Bellevue", "state": "WA"},
{"name": "Olympia", "state": "WA"}
]
}
If I were doing this in JavaScript, what I want to do would be something like this:
let object = JSON.parse( raw_json );
object.locations[0].state = "NM";
object.locations[1].state = "HI";
raw_json = JSON.stringify( object );
The trick is, I don't want to have to embed more knowledge about the structure of the JSON than is necessary to be able to perform my transformations, that way if the parts of the JSON that I'm not modifying were to change, the expression still works as intended. Ideally, I would use an expression in place of hard-coded array offsets. But I left that out of the JavaScript code, for brevity.
Does jmesPath support this use case? If so, what is the syntax?