JSON Tools

Parse, query, and transform JSON data

gebruder 63f8e73 925 B Updated

File contents

JSON Tools

Parse and transform JSON using jq.

Query

  • Pretty print: echo '<json>' | jq .
  • Get field: echo '<json>' | jq '.field'
  • Nested field: echo '<json>' | jq '.a.b.c'
  • Array element: echo '<json>' | jq '.[0]'
  • Array length: echo '<json>' | jq 'length'

Filter and transform

  • Select fields: echo '<json>' | jq '{name: .name, id: .id}'
  • Filter array: echo '<json>' | jq '.[] | select(.status == "active")'
  • Map: echo '<json>' | jq '[.[] | .name]'
  • Sort: echo '<json>' | jq 'sort_by(.date)'
  • Group: echo '<json>' | jq 'group_by(.type)'
  • Unique: echo '<json>' | jq '[.[].category] | unique'

File operations

  • Read and query: jq '.key' file.json
  • Compact: jq -c . file.json
  • Raw strings (no quotes): jq -r '.name' file.json
  • Convert to CSV: jq -r '.[] | [.name, .value] | @csv' file.json

gebruder/wirken/tree/main/skills/json-tools commit 63f8e73d99

Frequently asked questions

npx skillmds@latest add gebruder/json-tools