←back to thread

2039 points Gadiguibou | 1 comments | | HN request time: 0s | source
Show context
klausa ◴[] No.36491947[source]
`pbcopy` and `pbpaste` are one of my most-loved in the list.

Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.

replies(28): >>36492008 #>>36492015 #>>36492028 #>>36492101 #>>36492108 #>>36492229 #>>36492265 #>>36492890 #>>36492953 #>>36493037 #>>36493127 #>>36493336 #>>36493457 #>>36493802 #>>36494023 #>>36494242 #>>36494325 #>>36495379 #>>36495894 #>>36496866 #>>36497033 #>>36497293 #>>36497589 #>>36497973 #>>36498181 #>>36498558 #>>36498586 #>>36535798 #
lkbm ◴[] No.36494023[source]
Oh man. I recently threw together a "j2p" script to make converting between json and python dicts simpler, and combining it with pbcopy/pbpaste will make it so much better:

  #!/usr/bin/env python3
  import sys
  import json
  
  print(json.load(sys.stdin))
replies(1): >>36494402 #
atoav ◴[] No.36494402[source]
Or directly from the commandline:

    pbcopy | python -c 'import sys; import json; print(json.load(sys.stdin))' | pbpaste
replies(1): >>36505406 #
1. tomviner ◴[] No.36505406[source]
The Python json library is callable as a module:

    pbcopy | python -m json.tool | pbpaste
It has a load options:

    $ python -m json.tool --help
    usage: python -m json.tool [-h] [--sort-keys] [--no-ensure-ascii] [--json-lines] [--indent INDENT | --tab | --no-indent | --compact] [infile] [outfile]

    A simple command line interface for json module to validate and pretty-print JSON objects.

    positional arguments:
      infile             a JSON file to be validated or pretty-printed
      outfile            write the output of infile to outfile

    options:
      -h, --help         show this help message and exit
      --sort-keys        sort the output of dictionaries alphabetically by key
      --no-ensure-ascii  disable escaping of non-ASCII characters
      --json-lines       parse input using the JSON Lines format. Use with --no-indent or --compact to produce valid JSON Lines output.
      --indent INDENT    separate items with newlines and use this number of spaces for indentation
      --tab              separate items with newlines and use tabs for indentation
      --no-indent        separate items with spaces rather than newlines
      --compact          suppress all whitespace separation (most compact)