
Json Data Handling
- 277 installs
- 63 repo stars
- Updated July 18, 2026
- bobmatnyc/claude-mpm-skills
Parse, validate, transform, and serialize JSON safely across APIs, CLIs, and service boundaries with consistent schemas and error handling.
About
Teaches robust JSON data handling for backend and integration code: parsing untrusted input, schema validation, typed transforms, serialization, and clear errors for APIs, SaaS services, and CLI tools.
- Schema validation
- Safe parsing patterns
- Type-safe transforms
- Error handling for malformed JSON
- API contract consistency
Json Data Handling by the numbers
- 277 all-time installs (skills.sh)
- Ranked #1,418 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Data as of Aug 1, 2026 (Skillselion catalog sync)
npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill json-data-handlingAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 277 |
|---|---|
| repo stars | ★ 63 |
| Last updated | July 18, 2026 |
| Repository | bobmatnyc/claude-mpm-skills ↗ |
What it does
Parse, validate, transform, and serialize JSON safely across APIs, CLIs, and service boundaries with consistent schemas and error handling.
Files
JSON Data Handling
Working effectively with JSON data structures.
Python
Basic Operations
import json
# Parse JSON string
data = json.loads('{"name": "John", "age": 30}')
# Convert to JSON string
json_str = json.dumps(data)
# Pretty print
json_str = json.dumps(data, indent=2)
# Read from file
with open('data.json', 'r') as f:
data = json.load(f)
# Write to file
with open('output.json', 'w') as f:
json.dump(data, f, indent=2)Advanced
# Custom encoder for datetime
from datetime import datetime
class DateTimeEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.isoformat()
return super().default(obj)
json_str = json.dumps({'date': datetime.now()}, cls=DateTimeEncoder)
# Handle None values
json.dumps(data, skipkeys=True)
# Sort keys
json.dumps(data, sort_keys=True)JavaScript
Basic Operations
// Parse JSON string
const data = JSON.parse('{"name": "John", "age": 30}');
// Convert to JSON string
const jsonStr = JSON.stringify(data);
// Pretty print
const jsonStr = JSON.stringify(data, null, 2);
// Read from file (Node.js)
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('data.json', 'utf8'));
// Write to file
fs.writeFileSync('output.json', JSON.stringify(data, null, 2));Advanced
// Custom replacer
const jsonStr = JSON.stringify(data, (key, value) => {
if (typeof value === 'bigint') {
return value.toString();
}
return value;
});
// Filter properties
const filtered = JSON.stringify(data, ['name', 'age']);
// Handle circular references
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) return;
seen.add(value);
}
return value;
};
};
JSON.stringify(circularObj, getCircularReplacer());Common Patterns
Validation
from jsonschema import validate
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number", "minimum": 0}
},
"required": ["name", "age"]
}
# Validate
validate(instance=data, schema=schema)Deep Merge
def deep_merge(dict1, dict2):
result = dict1.copy()
for key, value in dict2.items():
if key in result and isinstance(result[key], dict) and isinstance(value, dict):
result[key] = deep_merge(result[key], value)
else:
result[key] = value
return resultNested Access
# Safe nested access
def get_nested(data, *keys, default=None):
for key in keys:
try:
data = data[key]
except (KeyError, TypeError, IndexError):
return default
return data
# Usage
value = get_nested(data, 'user', 'address', 'city', default='Unknown')Transform Keys
# Convert snake_case to camelCase
def to_camel_case(snake_str):
components = snake_str.split('_')
return components[0] + ''.join(x.title() for x in components[1:])
def transform_keys(obj):
if isinstance(obj, dict):
return {to_camel_case(k): transform_keys(v) for k, v in obj.items()}
elif isinstance(obj, list):
return [transform_keys(item) for item in obj]
return objBest Practices
✅ DO
# Use context managers for files
with open('data.json', 'r') as f:
data = json.load(f)
# Handle exceptions
try:
data = json.loads(json_str)
except json.JSONDecodeError as e:
print(f"Invalid JSON: {e}")
# Validate structure
assert 'required_field' in data❌ DON'T
# Don't parse untrusted JSON without validation
data = json.loads(user_input) # Validate first!
# Don't load huge files at once
# Use streaming for large files
# Don't use eval() as alternative to json.loads()
data = eval(json_str) # NEVER DO THIS!Streaming Large JSON
import ijson
# Stream large JSON file
with open('large_data.json', 'rb') as f:
objects = ijson.items(f, 'item')
for obj in objects:
process(obj)Remember
- Always validate JSON structure
- Handle parse errors gracefully
- Use schemas for complex structures
- Stream large JSON files
- Pretty print for debugging
{
"name": "json-data-handling",
"version": "1.0.0",
"category": "universal",
"toolchain": null,
"framework": null,
"tags": [
"debugging",
"frontend"
],
"entry_point_tokens": 53,
"full_tokens": 1136,
"requires": [],
"author": "bobmatnyc",
"updated": "2025-11-21",
"source_path": "json-data-handling.md",
"license": "MIT",
"source": "https://github.com/bobmatnyc/claude-mpm",
"created": "2025-11-21",
"modified": "2025-11-21",
"maintainer": "Claude MPM Team",
"attribution_required": true,
"repository": "https://github.com/bobmatnyc/claude-mpm-skills"
}