JSON to CSV with Hash Verification Workflow
Format messy JSON, convert to CSV for spreadsheets, and generate SHA-256 hashes for data integrity verification. Includes Bash, Python, and Node.js automation scripts.
The Problem
You receive API responses or database exports as minified JSON blobs that need to be validated, converted to CSV for stakeholders who use spreadsheets, and checksummed to prove data has not been tampered with. Doing each step with different tools and no verification creates data integrity risks.
Why This Workflow Matters
Data pipelines that lack integrity checks silently corrupt data. A JSON formatting error can break CSV conversion. A truncated export can go unnoticed without hash verification. This workflow builds a verifiable chain: validate → convert → checksum, so every downstream consumer trusts the data.
Workflow Overview
Step-by-Step Instructions
Format and validate the raw JSON
Paste your minified JSON into the JSON Formatter. It validates syntax (catches missing commas, unmatched brackets) and pretty-prints the output. Fix any errors before proceeding.
Generate a hash of the source data
Copy the formatted JSON and paste it into the Hash Generator. Generate a SHA-256 hash. This is your source-of-truth fingerprint — save it alongside the data.
Convert JSON to CSV
Paste the validated JSON array into the JSON to CSV Converter. It flattens nested objects and generates a downloadable CSV file with proper headers.
Verify round-trip integrity
Convert the CSV back to JSON (or re-hash the original JSON) and compare hashes. If the SHA-256 matches, the data is intact. Document the hash in your data manifest or README.
Before & After
Minified JSON blob, no verification
{"users":[{"id":1,"name":"Alice","email":"[email protected]","role":"admin"},{"id":2,"name":"Bob","email":"[email protected]","role":"viewer"}]}
# No way to verify data integrity
# No spreadsheet-friendly format
Formatted JSON + CSV + SHA-256 manifest
formatted.json → Pretty-printed, validated output.csv → id,name,email,role (2 rows) manifest.txt → sha256=a3f2b8c1... records=2
Automate This Workflow
Copy these scripts to automate the workflow in your preferred language:
$
Bash
# Format JSON with jq
cat raw-data.json | jq '.' > formatted.json
# Generate SHA-256 hash
SHA=$(sha256sum formatted.json | cut -d" " -f1)
echo "SHA-256: $SHA" > manifest.txt
# Convert JSON array to CSV with jq
jq -r '(.[0] | keys_unsorted) as $keys
| $keys, map([.[ $keys[] ]])[] | @csv' \
formatted.json > output.csv
# Verify integrity
echo "Records: $(wc -l < output.csv)"
echo "Hash: $SHA"
Py
Python
import json
import csv
import hashlib
# Load and format JSON
with open("raw-data.json") as f:
data = json.load(f)
formatted = json.dumps(data, indent=2)
# Generate SHA-256
sha256 = hashlib.sha256(formatted.encode()).hexdigest()
print(f"SHA-256: {sha256}")
# Convert to CSV
with open("output.csv", "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)
# Save manifest
with open("manifest.txt", "w") as f:
f.write(f"sha256={sha256}\nrecords={len(data)}")
JS
Node.js
const fs = require("fs");
const crypto = require("crypto");
// Load and format JSON
const raw = fs.readFileSync("raw-data.json", "utf8");
const data = JSON.parse(raw);
const formatted = JSON.stringify(data, null, 2);
// Generate SHA-256
const hash = crypto.createHash("sha256")
.update(formatted).digest("hex");
console.log(`SHA-256: ${hash}`);
// Convert to CSV
const headers = Object.keys(data[0]);
const csv = [headers.join(","),
...data.map(row =>
headers.map(h => JSON.stringify(row[h] ?? "")).join(",")
)
].join("\n");
fs.writeFileSync("output.csv", csv);
Frequently Asked Questions
Why hash the JSON before converting to CSV?
How do I handle nested JSON when converting to CSV?
address.city). Arrays are expanded into separate rows. For deeply nested structures, consider flattening with jq first.
What hash algorithm should I use for data manifests?
Can I automate this pipeline for daily API exports?
Related Workflows
Try These Tools Now
All tools in this workflow are free and work directly in your browser — no sign-up required.