my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.7 KiB

3 years ago
  1. # jsontools
  2. Handy command line tools for dealing with json data.
  3. To use it, add `jsontools` to the plugins array in your zshrc file:
  4. ```zsh
  5. plugins=(... jsontools)
  6. ```
  7. ## Usage
  8. Usage is simple... just take your json data and pipe it into the appropriate jsontool:
  9. - `pp_json`: pretty prints json.
  10. - `is_json`: returns true if valid json; false otherwise.
  11. - `urlencode_json`: returns a url encoded string for the given json.
  12. - `urldecode_json`: returns decoded json for the given url encoded string.
  13. ### Supports NDJSON (Newline Delimited JSON)
  14. The plugin also supports [NDJSON](http://ndjson.org/) input, which means all functions
  15. have an alternative function that reads and processes the input line by line. These
  16. functions have the same name except using `ndjson` instead of `json`:
  17. > `pp_ndjson`, `is_ndjson`, `urlencode_ndjson`, `urldecode_ndjson`.
  18. ### Examples
  19. - **pp_json**:
  20. ```console
  21. # curl json data and pretty print the results
  22. curl https://coderwall.com/bobwilliams.json | pp_json
  23. ```
  24. - **is_json**:
  25. ```console
  26. # validate if file's content conforms to a valid JSON schema
  27. $ is_json < data.json
  28. true
  29. # shows true / false and returns the proper exit code
  30. $ echo $?
  31. 0
  32. ```
  33. - **urlencode_json**:
  34. ```console
  35. # json data directly from the command line
  36. $ echo '{"b":2, "a":1}' | urlencode_json
  37. %7B%22b%22:2,%20%22a%22:1%7D
  38. ```
  39. - **urldecode_json**:
  40. ```console
  41. # url encoded string to decode
  42. $ echo '%7B%22b%22:2,%20%22a%22:1%7D' | urldecode_json
  43. {"b":2, "a":1}
  44. ```
  45. - **pp_ndjson**:
  46. ```console
  47. # echo two separate json objects and pretty print both
  48. $ echo '{"a": "b"}\n{"c": [1,2,3]}' | pp_ndjson
  49. {
  50. "a": "b"
  51. }
  52. {
  53. "c": [
  54. 1,
  55. 2,
  56. 3
  57. ]
  58. }
  59. ```