bash - re-organize object fields with jq -
i wondering if there way re-organize fields of object using jq.
i mean, given that
{ "prop1": 1, "prop2": { "nested": 0 }, "prop3": true }
i'd this
{ "prop1": 1, "prop3": true, "prop2": { "nested": 0 } }
i want choose order of fields (without consideration type of field or alphabetical order, choice :) )
thanks !
the safe option have generate json string manually properties ordered in way want them. there no guarantee order set properties on object preserved.
you can of function:
def inorder(names): names $names | . $obj | "{\($names | map("\(@json):\($obj[.])") | join(","))}" ;
then use it:
inorder(["prop1", "prop3", "prop2"])
keep in mind return string. you'll want raw output object.
Comments
Post a Comment