Created
October 26, 2018 16:02
-
-
Save waltervargas/0f6d1ba48c802d15e98baf13937e5857 to your computer and use it in GitHub Desktop.
Bash JSON check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
_json_valid(){ | |
local _STD_OUT_ERR | |
_STD_OUT_ERR=$( { jq type /dev/stdin <<< "${1}"; } 2>&1 ) | |
} | |
read -d '' -r _JSON <<EOB | |
{"widget": { | |
"debug": "on", | |
"window": { | |
"title": "Sample Konfabulator Widget", | |
"name": "main_window", | |
"width": 500, | |
"height": 500 | |
}, | |
"image": { | |
"src": "Images/Sun.png", | |
"name": "sun1", | |
"hOffset": 250, | |
"vOffset": 250, | |
"alignment": "center" | |
}, | |
"text": { | |
"data": "Click Here", | |
"size": 36, | |
"style": "bold", | |
"name": "text1", | |
"hOffset": 250, | |
"vOffset": 100, | |
"alignment": "center", | |
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" | |
} | |
}} | |
EOB | |
if _json_valid "${_JSON}"; then | |
echo "JSON valid for jq :)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment