0

I have a bunch of JSON files (fixtures) from which I need to delete a field if the "current" object happens to match a select filter.

I'm able to match the desired objects but I'm not sure how to perform the deletion of the field so that the object is modified in-place.

So far this is the closest I've gotten to:

jq '..|objects|select(.__typename == "MyType") | del(.delete_me)' fixture.json

But doesn't seem to work correctly, assignment of the field is straight forward I'm thinking I could probably try and use path as $paths and getpath to set the "parent" value with the output of del but I'm stuck and don't quite fully understand the functions.

Any help is really appreciated!

1 Answer 1

1

For "in-place" deletion of a key, you might find walk quite congenial:

walk(if type == "object" and .__typename == "MyType" 
     then del(.delete_me) else . end)
Sign up to request clarification or add additional context in comments.

1 Comment

Let me give it a try, seems clear enough

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.