
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
json-compact
Advanced tools
Create a downsized json file from tabular data, ie [{...},{...}] Optimized for GPT/LLM processing.
JSONcompact is a TypeScript/JavaScript library designed to convert complex JSON data into a compact, tabular format. This format is particularly suitable for processing and analysis with AI models like GPT-3. The library also provides functionality to revert this compacted data back to its original form. It offers an optional feature to round numerical values to a specified number of decimal places. The library is useful in scenarios where you need to minimize JSON size without losing the essence and structure of the data. You can expect a reduction in token size of >40% for larger data sets.
npm install json-compact
import JSONcompact from 'json-compact';
const originalData = [
{ name: "Alice", age: 30.123, occupation: "Engineer" },
{ name: "Bob", age: 25.456, occupation: "Designer" }
];
// Compact without rounding
const compacted = JSONcompact.compact(originalData);
console.log(compacted);
// Compact with rounding to 2 decimal places
const compactedRounded = JSONcompact.compact(originalData, undefined, 2);
console.log(compactedRounded);
const expandedData = JSONcompact.expand(compacted);
console.log(expandedData);
The library also supports compacting and expanding JSON strings directly.
const jsonDataString = JSON.stringify(originalData);
const compactedString = JSONcompact.compactedJSON(jsonDataString);
console.log(compactedString);
const expandedString = JSONcompact.expandedJSON(compactedString);
console.log(expandedString);
JSONcompact.compact(data, [description], [roundToDecimalPlaces])
Compacts an array of data objects or a JSON string into a tabular format.
data
: An array of objects or a JSON string representing the data to be compacted.description
: Optional. Custom description for the compacted data.roundToDecimalPlaces
: Optional. Number of decimal places to round numerical values to. If not provided, numbers are not rounded.JSONcompact.expand(data)
Expands the compacted data back into its original format.
data
: The compacted data object or a string in the compacted JSON format.Contributions are welcome! Please feel free to submit a pull request or open issues to improve the library.
This project is licensed under the MIT License.
FAQs
Create a downsized json file from tabular data, ie [{...},{...}] Optimized for GPT/LLM processing.
The npm package json-compact receives a total of 9 weekly downloads. As such, json-compact popularity was classified as not popular.
We found that json-compact demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.