Back to Blog
Developer Tools

Validate JSON Before Deployment โ€” Catch Syntax Errors Before They Reach Production

2026-06-03 4 min read

A single misplaced comma or trailing comma in a JSON config file can bring down a deployment. Here is why validating JSON before commit matters.

A malformed JSON config file can take down a production service instantly. It happens more often than people admit. You edit a config, miss a closing bracket, deploy, and suddenly your app won't start. JSON validation before deployment is a small habit with a large payoff.

What JSON validation checks

Basic validation confirms that your JSON is syntactically correct: balanced braces and brackets, properly quoted strings, no trailing commas, valid escape sequences. It doesn't check whether the values make business sense, just whether the structure is parseable.

Typical JSON syntax errors that are caught:

  • Trailing comma after the last item in an object or array
  • Single quotes instead of double quotes around strings
  • Unescaped special characters inside strings
  • Missing commas between key-value pairs
  • Comments (// comment is not valid JSON)

Add validation to your CI pipeline

The right place to validate JSON files is before they ever reach production. If you're using GitHub Actions, you can add a step that validates all JSON files in your repo:

# .github/workflows/validate.yml
- name: Validate JSON files
  run: |
    find . -name "*.json" -not -path "*/node_modules/*" | while read f; do
      python3 -m json.tool "$f" > /dev/null && echo "OK: $f" || exit 1
    done

This fails the build if any JSON file is malformed. No more accidentally deploying a broken config.

Validate in Node.js

// Simple validation
function isValidJson(str) {
  try {
    JSON.parse(str);
    return true;
  } catch {
    return false;
  }
}

// With error details
function validateJson(str) {
  try {
    return { valid: true, data: JSON.parse(str) };
  } catch (err) {
    return { valid: false, error: err.message };
  }
}

Schema validation goes further

Syntax validation tells you if JSON is parseable. Schema validation tells you if it has the right shape. Libraries like ajv let you define a JSON Schema and validate that your data matches it. This catches issues like a required field being missing or a number field containing a string.

import Ajv from "ajv";
const ajv = new Ajv();

const schema = {
  type: "object",
  properties: {
    name: { type: "string" },
    port: { type: "number" },
  },
  required: ["name", "port"],
};

const validate = ajv.compile(schema);
const valid = validate(data);
if (!valid) console.error(validate.errors);

Quick browser-based validation

For a quick check without setting anything up, paste your JSON into our JSON Formatter. It validates and formats simultaneously, and shows you exactly which line has an error. Takes five seconds and works for any JSON, including large config files.

json validate deployment syntax developer

More Articles