JSON Tools

Data

Format, minify, validate, flatten, and inspect JSON structures.

Import

Import
import { json } from 'toolmetry';

API Reference

FunctionParametersReturnsDescription
jsonFormatinput: string, indent?: numberstringFormat/prettify JSON
jsonMinifyinput: stringstringMinify JSON string
jsonValidateinput: string{ valid, error, position }Validate JSON and return error info
jsonGetTypeinput: stringstringGet the type of a JSON value
jsonStatsinput: string{ type, keys, depth, size }Get statistics about a JSON structure
jsonFlatteninput: stringRecord<string, unknown>Flatten JSON to dot-notation object

Examples

Format & Minify
import { jsonFormat, jsonMinify } from 'toolmetry';

const ugly = '{"name":"John","age":30}';

const pretty = jsonFormat(ugly, 2);
// Formatted with 2-space indent

const mini = jsonMinify(ugly);
// '{"name":"John","age":30}'
Validate
import { jsonValidate } from 'toolmetry';

const result = jsonValidate('{"valid": true}');
// { valid: true, error: null, position: null }
Stats & Flatten
import { jsonStats, jsonFlatten } from 'toolmetry';

const stats = jsonStats('{"a":1,"b":{"c":2}}');
// { type: "object", keys: 2, depth: 2, size: 20 }

const flat = jsonFlatten('{"a":{"b":1}}');
// { "a.b": 1 }

Try It Live