add the old snippet md files

This commit is contained in:
Travis Shears 2025-06-05 16:20:57 +02:00
parent fc0dd204c7
commit bcf8313a4b
110 changed files with 3048 additions and 0 deletions

View file

@ -0,0 +1,28 @@
---
title: "jq json processor"
date: 2020-01-30T09:10:56+01:00
draft: false
snippet_types: ["JSON", "curl", "jq"]
---
One of my oldest snippets is how to [Pretty print JSON](/snippets/pretty-print-json)
in the shell. This method works great for simple things where you just need to get an idea
of the JSON structure, it has the bonus of using python which you probably already have
installed. The problem is when you want to do more complex tasks it is quite limited in terms of
parsing. Thats where [jq](https://stedolan.github.io/jq) comes in
```shell
$ curl https://review-noticket-xxxxxxxx.eu/xxxxx/static/loadable-stats.json | jq '.entrypoints .sharedHeader .assets' | rg --invert-match map`
```
Simply piping to [jq](https://stedolan.github.io/jq) pretty prints the JSON
but by passing a query string, ex **".entrypoints .sharedHeader .assets"**,
you dig into the JSON and easily get what you need. This is easily
combinable with other shell utilities like in the example above which gets a
list of asset URLs than uses ripgrep invert-match to clean out the source map
URLs from the list. This is now my perfered way of working with JSON in the shell.
source:
- [brew formulae](https://formulae.brew.sh/formula/jq)
- [jq docs](https://formulae.brew.sh/formula/jq)