JSON compression for LLMs
Send an LLM less JSON without breaking the payload shape.
Large JSON responses are common agent context: cloud inventories, test output, search results, and API records. Tokz parses structured payloads, selects relevant records and fields, and preserves a valid JSON result rather than cutting text at an arbitrary character count.
const result = await tokz.compress(JSON.stringify(apiResponse), {
query: "Which deployment failed and what is its ID?",
targetRatio: 0.4,
preserve: { jsonPaths: ["$.deployments[*].id"] },
});A valid parse is a minimum contract
A shorter JSON string that no longer parses is not useful to an application or a model tool. Structural compression maintains JSON validity while selecting material from the original payload.
Preserve fields with an explicit rule
Use JSON paths for IDs and other fields your workflow must retain. Salience ranking can guide selection, but a required identifier deserves an explicit contract.
Keep representative structure
Schemas, relevant status fields, and selected records give a model more useful orientation than an arbitrary run of early rows. Inspect the output on real payloads before making it a production policy.
Limitations
The selected JSON is a context view, not an archival transformation. Keep the source when the application must reconstruct dropped records or make a later decision with different intent.