Format, minify, validate, flatten, and inspect JSON structures.
import { json } from 'toolmetry';| Function | Parameters | Returns | Description |
|---|---|---|---|
jsonFormat | input: string, indent?: number | string | Format/prettify JSON |
jsonMinify | input: string | string | Minify JSON string |
jsonValidate | input: string | { valid, error, position } | Validate JSON and return error info |
jsonGetType | input: string | string | Get the type of a JSON value |
jsonStats | input: string | { type, keys, depth, size } | Get statistics about a JSON structure |
jsonFlatten | input: string | Record<string, unknown> | Flatten JSON to dot-notation object |
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}'import { jsonValidate } from 'toolmetry';
const result = jsonValidate('{"valid": true}');
// { valid: true, error: null, position: null }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 }