I'd like to remove a property with a specific name from an object. For example given:
const x = {
numprop: 3, // important comment about the numprop
filter: {
test: "hi",
},
objprop: {
a: "a"
},
}
I'd like to remove the filter property and end up with:
const x = {
numprop: 3, // important comment about the numprop
objprop: {
a: "a"
},
}
My first attempt was grasp 'obj.props[key=#filter]' -R '' but this leaves an extra comma where the property was removed.
I also tried grasp 'obj! > prop[key=#filter]' -R '{\n{{.props[key!=#filter] | join ",\n" }}\n}' which does work, but since it rewrites the whole object it also removes any comments on the parts of the object I want to keep. Is there an alternative to avoid this?
I'd like to remove a property with a specific name from an object. For example given:
I'd like to remove the
filter
property and end up with:My first attempt was
grasp 'obj.props[key=#filter]' -R ''
but this leaves an extra comma where the property was removed.I also tried
grasp 'obj! > prop[key=#filter]' -R '{\n{{.props[key!=#filter] | join ",\n" }}\n}'
which does work, but since it rewrites the whole object it also removes any comments on the parts of the object I want to keep. Is there an alternative to avoid this?