jj icon indicating copy to clipboard operation
jj copied to clipboard

Can you delete from objects in an array?

Open nixta opened this issue 6 years ago • 1 comments
trafficstars

Let's say I have JSON that includes an array, each element of which is a JSON object. Can I modify those objects?

{
  "items" : [
    { "geometry" : [0,0], "properties": { "name": "Null Island", "area": 1000 } },
    { "geometry" : [40.7128,-74.0060], "properties": { "name": "Manhattan", "area": 14604 } }
  ]
}

I can select and view items.#.properties.area, but I'd like to delete area from each item. Is that possible but I'm just doing it wrong?

nixta avatar Nov 21 '18 19:11 nixta

I'm also interested in if there is a way to delete an entire object from the array if you don't know the index... i.e. by specifying a condition it would be nice to say jj -D items.#[item_name="x"] or jj -D items.#[properties.name="Manhattan"] at the moment this seems to result in error: cannot delete value from a complex path :-( so I'm having to resort back to jq I'll probably raise new ticket if nobody can suggest a work around for this.

c-nv-s avatar Oct 10 '23 15:10 c-nv-s