Commands tagged json (35)

  • Compactly display a bitcoin-cli fee estimate in satoshis/Byte, sat/B, date time stamp. Change the 6 to the desired number of confirmations. Display in btc/KB unit of measure: printf %g "$(bccli estimatesmartfee 6 "ECONOMICAL" | jq .feerate)";printf " btc/KB estimated feerate for 6 confirmations\nMultiply by 100,000 to get sat/B\n"; Two settings for estimate mode are "ECONOMICAL". "CONSERVATIVE" is the same as "UNSET" # jq is a json filter. sudo apt-get install jq Show Sample Output


    0
    printf %g "$(bitcoin-cli estimatesmartfee 6 "ECONOMICAL" | jq .feerate*100000)";printf " sat/B estimated feerate for 6 confirmations as of $(date +%c)\nDivide by 100,000 to get btc/KB\n"
    deinerson1 · 2018-06-20 13:40:32 0
  • * Output is jq compatible * Output is single lines - unix compatible * Multiple files supported


    0
    perl -MYAML::XS=LoadFile -MJSON::XS=encode_json -e 'for (@ARGV) { for (LoadFile($_)) { print encode_json($_),"\n" } }' *.yaml
    bsb · 2017-11-17 09:33:56 0
  • It's a tool of the great csvkit https://csvkit.readthedocs.io/en/1.0.2/scripts/csvjson.html


    0
    csvjson -k "CityID" city.csv
    aborruso · 2017-06-28 06:36:32 0
  • Based / Inspired by malathion's below command http://www.commandlinefu.com/commands/view/20528/convert-csv-to-json Is written for python3 and is very easy to use csv2json *csv will convert all files ending in csv to json eg csv2json file.csv will output a file to file.json Validity of json tested in python3 and below site https://jsonformatter.curiousconcept.com/


    0
    csv2json() { for file in $@; do python -c "import csv,json,fileinput; print(json.dumps(list(csv.reader(fileinput.input()))))" "$file" 1> "${file%%csv}json"; done; }
    snipertyler · 2017-06-28 04:28:32 0
  • Requires installing json2yaml via npm: npm install -g json2yaml (can also pipe from stdin) Ref: https://www.npmjs.com/package/json2yaml


    0
    json2yaml ./example.json > ./example.yml
    quaddo · 2017-06-13 22:25:08 0
  • Replace 'csv_file.csv' with your filename.


    3
    python -c "import csv,json;print json.dumps(list(csv.reader(open('csv_file.csv'))))"
    malathion · 2017-05-17 19:35:53 0
  • # Usage: ftagmarks TAG BOOKMARKS.JSON ftagmarks Bash ~/.mozilla/firefox/*.default/bookmarkbackups/bookmarks-*.json Tag can be partial matching, e.g. input 'Bas' or 'ash' will match 'Bash' tag. # Exact tag matching: ftagmark(){ jq -r --arg t "$1" '.children[] as $i|if $i.root == "tagsFolder" then ([$i.children[] as $j|{title: ($j.title), urls: [$j.children[].uri]}]) else empty end|.[] as $k|if $k.title == $t then $k.urls else empty end|.[]?' "$2"; } Usage: ftagmark TAG BOOKMARKS.JSON # List all tags: ftagmarkl(){ jq -r '.children[] as $i | if $i.root == "tagsFolder" then $i.children[].title else empty end' "$1"; } Usage: ftagmarkl BOOKMARKS.JSON # Requires: `jq` - must have CLI JSON processor http://stedolan.github.io/jq Show Sample Output


    0
    ftagmarks(){ jq -r --arg t "$1" '.children[] as $i|if $i.root == "tagsFolder" then ([$i.children[] as $j|{title: ($j.title), urls: [$j.children[].uri]}]) else empty end|.[] as $k|if ($k.title|contains($t)) then $k.urls else empty end|.[]?' "$2"; }
    qwertyroot · 2016-12-24 15:12:04 0

  • 2
    curl -s httpbin.org/ip | jq -r .origin
    tebeka · 2016-08-11 04:20:48 1
  • json2yaml is an npm package https://www.npmjs.com/package/json2yaml You must have node and npm installed to install/use this Show Sample Output


    0
    json2yaml result.json
    ptotaram · 2016-05-25 14:32:30 0
  • Grabs the first JSON file in the directory, reads its keys, prints TSV, then prints all the json files' values as TSV. Nested objects appear as json. Unhappy times if your json has literal tabs in it. Show Sample Output


    0
    jq -r 'keys | join("\t")' $(ls -f *.json | head -1) && jq -Sr 'to_entries | [ .[] | .value | tostring ] | join("\t")' *.json
    drjeats · 2016-04-08 23:30:30 0
  • The only pre-requisite is jq (and curl, obviously). The other version used grep, but jq is much more suited to JSON parsing than that. Show Sample Output


    -1
    btc() { echo "1 BTC = $(curl -s https://api.coindesk.com/v1/bpi/currentprice/$1.json | jq .bpi.\"$1\".rate | tr -d \"\"\") $1"; }
    benjabean1 · 2015-09-19 02:49:30 0
  • If you tried the other Python version of Convert JSON to YAML and you end up with lines that has "!!python/unicode", this version of the command is for you.


    1
    python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, allow_unicode=True)' < foo.json > foo.yaml
    renoirb · 2015-01-20 15:58:29 0
  • This is based on __unixmonkey73469__ answer. You will need to supply `--multiline 1` option to JSON importer if your .json is multiline (i.e. it was prettyfied) And you still need catmandu installed via `cpanm Catmandu`


    1
    catmandu convert JSON --multiline 1 to YAML < file.json > file.yaml
    pavelkaroukin · 2014-09-29 16:45:24 0

  • 0
    ogr2ogr -f GeoJSON output.geojson input.shp
    wille · 2014-08-27 12:14:24 0
  • Leave out pygmentize or `pip install pygments` first. Show Sample Output


    5
    alias pp='python -mjson.tool|pygmentize -l js'
    wires · 2014-05-22 10:29:44 2
  • You need to install the Catmandu Perl module via `cpanm Catmandu`


    1
    catmandu convert JSON to YAML < file.json > file.yaml
    unixmonkey73469 · 2014-02-25 08:27:05 0

  • 0
    ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' < file.yml > file.json
    vertis · 2013-12-03 03:16:42 0
  • For situations where you keep JSON in a VCS and you want your diffs to be sane, such as within a Chef configuration repo.


    1
    cat foo.json | python -mjson.tool
    jeffgage · 2013-05-06 20:11:05 0
  • since Mozai said that JSON is a subset of YAML ;)


    -6
    mv data.{json,yaml}
    bunam · 2013-04-25 07:47:32 0
  • Valid JSON is a subset of YAML; no transformation is necessary; however, YAML has many syntax features that are not valid JSON, so you can't do the reverse as easily.


    -8
    cat data.json >data.yml
    Mozai · 2013-04-25 04:09:58 0

  • 11
    ruby -ryaml -rjson -e 'puts YAML.dump(JSON.parse(STDIN.read))' < file.json > file.yaml
    wejn · 2013-04-24 07:20:37 0
  • Convert JSON to YAML. Note that you'll need to have PyYaml installed.


    9
    python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)' < file.json > file.yaml
    tebeka · 2013-04-24 00:31:39 2
  • Converts YAML file to JSON. Note that you'll need to install PyYAML. Also some YAML data types (like dates) are not supported by JSON).


    4
    python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < file.yaml > file.json
    tebeka · 2013-04-24 00:28:55 0

  • 0
    uniq -c | sed -r 's/([0-9]+)\s(.*)/"\2": \1,/;$s/,/\n}/;1i{'
    qistoph · 2013-04-13 16:48:59 0
  • Uses pygmentize and python to create indented and colorized JSON output Show Sample Output


    2
    alias pp='python -mjson.tool | pygmentize -l javascript'
    wires · 2012-10-16 13:55:38 0
  •  1 2 > 

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Numeric zero padding file rename
rename file name with fixed length nomeric format pattern

Inverted cowsay
It's quite fun to invert text using "flip.pl" (ref: http://ubuntuforums.org/showthread.php?t=2078323 ). Slightly more challenging is to flip a whole "cowsay". :-)

BASH one-liner to get the current week number
Not as cool as the python example, but it still works.

Virtualbox: setup hardware
where - memory 256 assign 256 Mb RAM - acpi on enable ACPI (mandatory if you use Winfog 2000 - ioapic off disable the IO APIC. Not useful if you use one CPU (on virtual machine or a 32 bit operative system). As ACPI, this switch is mandatory for Winbug 2000 - pae on enable the Phisical Address Extension how to use more than 4Gb of RAM on x86 CPU - hwvirtex on enables hardware virtualization extensions for microprocessors that have this feature (which should be also enabled in the BIOS of the motherboard) - nestedpaging on allows part of the processes of memory management hardware are made directly

Remove all zero size files from current directory (not recursive)

copy working directory and compress it on-the-fly while showing progress
What happens here is we tell tar to create "-c" an archive of all files in current dir "." (recursively) and output the data to stdout "-f -". Next we specify the size "-s" to pv of all files in current dir. The "du -sb . | awk ?{print $1}?" returns number of bytes in current dir, and it gets fed as "-s" parameter to pv. Next we gzip the whole content and output the result to out.tgz file. This way "pv" knows how much data is still left to be processed and shows us that it will take yet another 4 mins 49 secs to finish. Credit: Peteris Krumins http://www.catonmat.net/blog/unix-utilities-pipe-viewer/

Beep siren
Infinitely plays beeps with sinusoidally changing sound frequency. Ideal for alarm on an event.

Use a var with more text only if it exists
See "Parameter Expansion" in the bash manpage. They refer to this as "Use Alternate Value", but we're including the var in the at alternative.

Take a file as input (two columns data format) and sum values on the 2nd column for all lines that have the same value in 1st column
Example: $ cat

List your MACs address
No need for the ls -r and a sort is also not really needed.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: