A lightweight Node.js tool to parse, clean, and normalize messy JSON — especially helpful when dealing with stringified or deeply nested JSON from legacy systems or third-party APIs.
json-cleaner/
├── rawdata.txt # 🔸 Raw input with messy JSON
├── cleanJson.json # ✅ Cleaned output (auto-generated)
└── main.js # 🧠 Script with core logic
- Reads raw JSON from
rawdata.txt
- Parses & cleans:
data.updated.updated
— may be a stringified JSON array- Each
invoice.attachment
— possibly stringified JSON objects
- Safely transforms these fields into real JSON structures
- Outputs a clean, pretty-formatted JSON file →
cleanJson.json
If a field like attachment
fails to parse, the script logs a warning and keeps going:
⚠️ Could not parse attachment for invoice: INV-12345
git clone https://github.com/yourusername/json-cleaner.git
cd json-cleaner
Drop your raw/messy JSON into a file named:
rawdata.txt
Make sure Node.js is installed, then run:
node main.js
If successful, you'll see:
✅ Clean JSON written to cleanJson.json
- Node.js v12+
- No external libraries — uses native
fs
andpath
modules only
- Cleaning double-encoded JSON from outdated APIs
- Normalizing inconsistent data before importing into a database
- Quickly validating and formatting malformed JSON for automation or manual QA
Licensed under the MIT License
Got ideas or improvements? Open an issue or submit a pull request — contributions are warmly welcome!
- I cleaned up repetition, reduced emoji clutter, and added visual hierarchy for easy reading.
- You can replace
"Your Name"
and links with real content. - Want a badge section (e.g.,
node version
, license)? I can add that too.