I have a series of events represented in a JSON array. I want to move data in the fields of earlier events to a later event. Is there a way to do this with jq?
Here is an example of what I'm looking for.
Input:
[
{"verb":"set", "object":"parameter1", "value":1},
{"verb":"set", "object":"parameter2", "value":2},
{"verb":"run", "object":"simulation"},
{"verb":"set", "object":"parameter1", "value":10},
{"verb":"set", "object":"parameter2", "value":20},
{"verb":"run", "object":"simulation"}
]
Here is my desired output:
[
{"verb":"set", "object":"parameter1", "value":1},
{"verb":"set", "object":"parameter2", "value":2},
{"verb":"run", "object":"simulation", "value":{
"parameter1":1, "parameter2":2}
},
{"verb":"set", "object":"parameter1", "value":10},
{"verb":"set", "object":"parameter2", "value":20},
{"verb":"run", "object":"simulation", "value":{
"parameter1":10, "parameter2":20}
}
]
It seems like I could use variables to do this, but I don't understand how to tell jq to associate the 1 and 2 with the first "run" event and 10 and 20 with the second "run" event.