jq
jq copied to clipboard
Add in-place modification (expression) shorthand in objects
Just as {"a": .a}
is shortened into {a}
, I shortened {"a": .a | expr}
into {a | expr}
.
This is unambiguous because jq
doesn't accept bare expressions inside object definitions.
I added tests and a paragraph in the manual, let me know if it's not clear enough (I'm not a native speaker).
Thank you for the awesome project :D
Comparisons
Selecting and modifying specific fields
The syntax stays consistent between selection and in-place processing
# Before:
echo '{"title": "Hello", "foo": 1, "bar": 2}' | ./jq '{foo, "title": .title | ascii_upcase}'
# After:
echo '{"title": "Hello", "foo": 1, "bar": 2}' | ./jq '{foo, title | ascii_upcase}'
# Output:
# {"foo": 1, "title": "HELLO"}
Modifying specific fields (patching)
Variant 1: Works better when modifying a value nested deeply in .
Variant 2: Increases focus on the expression itself, by removing the "noisy" syntax ("a": .a
)
# Before:
echo '{"title": "Hello", "foo": 1, "bar": 2}' | ./jq '.title |= ascii_upcase'
echo '{"title": "Hello", "foo": 1, "bar": 2}' | ./jq '. + {"title": .title | ascii_upcase}'
# After:
echo '{"title": "Hello", "foo": 1, "bar": 2}' | ./jq '. + {title | ascii_upcase}'
# Output:
# {"title": "HELLO", "foo": 1, "bar": 2}
Nested selection
It now resembles GraphQL queries, which are familiar to many devs, which should reduce the learning curve for them.
# Before:
echo '{"hello": {"world": {"foo": 1, "bar": 2}, "there": 3}, "misc": 4}' | ./jq '{"hello": .hello | {"world": .world | {foo}, there}}'
echo '{"hello": {"world": {"foo": 1, "bar": 2}, "there": 3}, "misc": 4}' | ./jq '{"hello": {"world": {"foo": .hello.world.foo}, "there": .hello.there}'
# After:
echo '{"hello": {"world": {"foo": 1, "bar": 2}, "there": 3}, "misc": 4}' | ./jq '{hello | {world | {foo}, there}}'
# Output:
# {"hello": {"world": {"foo": 1}, "there": 3}}
AppVeyor CI seems broken, something with MSYS's PGP signature