JQ CHEATSHEET
=============
author: willee

Given next example, we're going to perform few typical operations:

    echo '{"a":["123"],"b":["234"],"c":["555"]}'

Rename field a to e:

    # simple way
    jq -c '{e:.a,b,c}'

    # actual rename
    jq -c 'with_entries(if .key == "a" then {key:"e",value} else . end)'

Remove field a:

    jq -c 'with_entries(select(.key != "a"))'

    # which is shorthand to:
    jq -c 'to_entries|map(select(.key != "a"))|from_entries'

Add element to field a:

    jq -c '. + {a:["222",.a[]]}'
    jq -c '.a += ["222"]'

Combine fields a and b:

    jq -c '. + {d: (.a + .b)}'

Complex examples:

    jq -c '. + (.a|= null) | if (.a|length)> 0 then . else empty end'

    # this one works with jsonlines of next form
    echo '{"names":["garcon","doorman"],"accounts":["2444111","244222"]}' | \
        jq -c -M 'if contains({"names":["garcon"]}) then \
        ((.accounts|=. + [2444555]) | (.names |= . - ["garcon"])) \
        else . end'

Convert objects to array of objects:

    jq -c 'to_entries|map({(.key):.value})'

