-
-
Save sudocurse/baac2fe9afebfc4a0488ccc2bcc680a4 to your computer and use it in GitHub Desktop.
Revisions
-
sudocurse revised this gist
Apr 29, 2020 . 1 changed file with 29 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,34 @@ # back to json. # The newline in the middle of the sed command is for BSD compatibility # # Still one problem: # - top-level arrays flatten to "[0].asdf" which cause invalid path expressions # The only hack I can think of right now for this is to wrap top level arrays # as a value in a pair in the top level object: # sed -E 's/(^\[[0-9]\])/.TLA\1/g' # along with the <<< '{"TLA":[]}' listed below instead of <<< '{}' # # Doing so would produce the following: # % echo '["g", 3, "throw"]' | catj | sed -E 's/(^\[[0-9]\])/.TLA\1/g' | uncatj # { # "TLA": [ # "g", # 3, # "throw" # ] # } # This ugly change also forces an extra element into normal objects: # # % echo '.HostConfig.PortBindings.HostIp = ""' | uncatj # { # "TLA": [], # "HostConfig": { # "PortBindings": { # "HostIp": "" # } # } # } # I hate it but it works ( jq -r "$(sed -E 's/(^\[[0-9]\])/.TLA\1/g ; s/$/ |/;$a\ .')" <<< '{"TLA":[]}' ) < "${1:-/dev/stdin}" -
sudocurse revised this gist
Apr 29, 2020 . 1 changed file with 16 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,16 @@ #!/bin/bash # # Converts flat json such as: # # .clients[0].id = "59761c23b30d971669fb42ff" # .clients[0].isActive = true # .clients[0].age = 36 # # back to json. # The newline in the middle of the sed command is for BSD compatibility # # Still some problems: # - top-level arrays flatten to "[0].asdf" which cause invalid path expressions ( jq -r "$(sed 's/$/ |/;$a\ .')" <<< '{}' ) < "${1:-/dev/stdin}" -
sudocurse revised this gist
Apr 29, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ jq -r --stream ' .[0] | map( if type == "number" then "[" + tostring + "]" else "." + "\"" + . + "\"" end ) | add ) + " = " + (.[1] | @json) -
sudocurse revised this gist
Apr 29, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ #!true -
sudocurse revised this gist
Apr 29, 2020 . 2 changed files with 1 addition and 21 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,4 +17,4 @@ jq -r --stream ' end ) | add ) + " = " + (.[1] | @json) ' < "${1:-/dev/stdin}" This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +0,0 @@ -
sudocurse revised this gist
Apr 29, 2020 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #!/bin/bash # # Outputs JSON paths. # # Based on https://news.ycombinator.com/item?id=20264654 # # Usage: # curl -s https://raw.githubusercontent.com/sitepoint-editors/json-examples/master/src/db.json | ./jsonpaths jq -r --stream ' select(length > 1) | ( .[0] | map( if type == "number" then "[" + tostring + "]" else "." + . end ) | add ) + " = " + (.[1] | @json) ' -
fernandoacorreia revised this gist
Jun 29, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/bash # # Outputs JSON paths. # # Based on https://news.ycombinator.com/item?id=20264654 # -
fernandoacorreia created this gist
Jun 29, 2019 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #!/bin/bash # # Displays JSON paths. # # Based on https://news.ycombinator.com/item?id=20264654 # # Usage: # curl -s https://raw.githubusercontent.com/sitepoint-editors/json-examples/master/src/db.json | ./jsonpaths jq -r --stream ' select(length > 1) | ( .[0] | map( if type == "number" then "[" + tostring + "]" else "." + . end ) | add ) + " = " + (.[1] | @json) '