How to Validate JSON in Command Line

Published April 2025 · 3 min read

Using jq (Best)

# Validate and pretty-print
jq . file.json

# Just validate (no output)
jq empty file.json && echo "Valid" || echo "Invalid"

Using Python (No Install Needed)

python3 -m json.tool file.json

# Or validate a string
echo '{"name":"John"}' | python3 -m json.tool

Using Node.js

node -e "JSON.parse(require('fs').readFileSync('file.json'))"

Windows PowerShell

Get-Content file.json | ConvertFrom-Json

Pipe from curl

curl -s https://api.example.com/data | jq .
curl -s https://api.example.com/data | python3 -m json.tool

Online Alternative

Use our JSON Formatter & Validator for a visual experience.

Related