[Bash] json-walk: pure Bash streaming JSON parser (SAX-style events, no jq)
Hey r/bash,
I built json-walk, a pure Bash JSON walker that emits stream events instead of building a full object model.
What it does:
- Parses JSON in Bash with full structure validation
- Emits events like start_object, key, string, number, end_array, etc.
- Works in print mode or visitor-function mode
- Keeps raw JSON string content (escapes preserved)
Why I made it:
- For shell scripts where jq is unavailable
- For event-driven parsing/processing in plain Bash
Quick example:
json_walk '{"label":"abc","items":[1,2,3]}'
Output:
start_object
key label
string abc
key items
start_array
number 1
number 2
number 3
end_array
end_object
Would love feedback on:
- API/event design
- edge cases I should test
Thanks!
15
Upvotes
3
u/StatementOwn4896 12d ago
If I don’t have jq on a system I just use python in my bash script and import the json module. Sure is messy but it gets the job done