npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-compact

v1.1.3

Published

Create a downsized json file from tabular data, ie [{...},{...}] Optimized for GPT/LLM processing.

Downloads

8

Readme

README for JSONcompact

Overview

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.

Features

  • Compact: Converts a JSON array of objects into a compact format with a descriptive header, reducing the size of the JSON data.
  • Optional Rounding: Option to round numerical values to a specified number of decimal places.
  • Expand: Reverts the compacted data back to its original JSON format.
  • Customizable Description: Allows for a custom description for the compacted data, aiding in clarity and context for AI models.
  • Support for String and Object Input: Accepts JSON data as both string and object formats.

Installation

npm install json-compact

Usage

Importing the Library

import JSONcompact from 'json-compact';

Compacting JSON Data

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);

Expanding Compacted Data

const expandedData = JSONcompact.expand(compacted);
console.log(expandedData);

Working with JSON Strings

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);

API Reference

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.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open issues to improve the library.

License

This project is licensed under the MIT License.