Skip to content

Latest commit

 

History

History
45 lines (40 loc) · 1.22 KB

README.md

File metadata and controls

45 lines (40 loc) · 1.22 KB

Simple Json parser for Bash

That code work at least on Bash 3.2.57 and above.
This is a pure Bash implementation with no dependencies.

ATTENTION:

Maybe there are some unimplemented important things. If anyone need anything from it, please contact to me, and i will try to do it.

ATTENTION: It's works slowly with big JSON documents.
Please, try it:
git clone https://github.com/lirik90/bashJsonParser.git
bash bashJsonParser/example.sh
Or something like that:
source <(curl -s -L -o- https://github.com/lirik90/bashJsonParser/raw/master/jsonParser.sh)
JSON='{"error": "Error message text"}'
JSON=$(minifyJson "$JSON")
echo "Message is: $(parseJson "$JSON" error)"

For integrate to your project:

  1. Copy code from jsonParser.sh file
  2. Get JSON from something place
read -d '' JSON << EOF
[{
  "name": "Leanne Graham",
  "company": {
    "name": "Romaguera-Crona",
  }
}]
EOF
  1. If your JSON is 'pretty' formatted wrap it with minify function like bellow:
JSON=$(minifyJson "$JSON")
  1. Choose field witch you want to parse
company=$(parseJson "$JSON" 0 company name)
echo "Company is: $company"