Python public

JSON Config Validate

Share this script safely, inspect its metadata, and copy the exact command you need.

Dashboard

Ready to run

One-liner

Copy the command, then review before execution.
curl -fsSL https://runny.sh/r/9WMJ5JKQGH2F | python3

Current version: 1.1 · Updated by Godmode · 2026-09-07 02:38:59.645

At a glance

Script metadata

Slug
9WMJ5JKQGH2F
Fetches
0
Size
1600 B · 62 lines
Expires
never
Last fetch
Created
2026-09-07 00:36:01.122
Description
Parse JSON files from argv or the current directory

Readable before runnable

Preview

#!/usr/bin/env python3
# JSON config validate
# Read-only: json.load files from argv, or *.json in the current directory.
# Exit 0 if every file parses, 1 if none found, 2 if a file is invalid JSON.
# Hosted on Runny.sh. Review the script page before you run it.

from __future__ import annotations

import glob
import json
import sys
from pathlib import Path


def validate(path: Path) -> int:
    try:
        with path.open("r", encoding="utf-8") as fh:
            json.load(fh)
    except FileNotFoundError:
        print(f"{path}: CRITICAL missing")
        return 2
    except json.JSONDecodeError as exc:
        print(f"{path}: CRITICAL invalid JSON ({exc.msg} at line {exc.lineno})")
        return 2
    except OSError as exc:
        print(f"{path}: CRITICAL {exc}")
        return 2
    print(f"{path}: OK")
    return 0


def main() -> int:
    print("=== JSON config validate ===")
    print(f"Cwd:      {Path.cwd()}")
    if len(sys.argv) > 1:
        files = [Path(arg) for arg in sys.argv[1:]]
    else:
        files = [Path(p) for p in sorted(glob.glob("*.json"))]
    print(f"Files:    {len(files)}")
    print()
    if not files:
        print("No JSON files given and no *.json in cwd")
        print("Result: WARNING")
        return 1
    worst = 0
    for path in files:
        rc = validate(path)
        if rc > worst:
            worst = rc
    print()
    if worst == 0:
        print("Result: HEALTHY")
    elif worst == 1:
        print("Result: WARNING")
    else:
        print("Result: CRITICAL")
    return worst


if __name__ == "__main__":
    sys.exit(main())

Raw endpointhttps://runny.sh/r/9WMJ5JKQGH2F

See something unsafe?

Report this script

Tell us why it should come down. Anyone can also report a URL at /abuse.

Restore revision