
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
llm-json-parser
Advanced tools
LLM JSON Parser is a groundbreaking TypeScript library designed to parse and reconstruct even the most severely broken JSON data using a predefined schema ( useful to parse json output by LLM ). This library pushes the limits of what is possible in JSON p
LLM JSON Parser is a groundbreaking TypeScript library designed to parse and reconstruct even the most severely broken JSON data using a predefined schema ( useful to parse json output by LLM ). This library pushes the limits of what is possible in JSON parsing, capable of extracting meaningful data from severely damaged JSON strings that would be unreadable by conventional parsers.
The main motivation for creating the LLM JSON Parser is to solve the frequent issue where large language models (LLMs) produce broken JSON outputs. In many cases, reprocessing the request is required, wasting time and resources. This parser allows for recovering valuable data without needing to rerun the entire process.
Here’s how to quickly get started with the LLM JSON Parser:
import { parseJSON } from './llm-json-parser';
const extremelyBrokenJSON = `
name John Doe
age: 30 picoupicou
email john@example.com
hobbies: [reading cycling
}
`;
const schema = {
name: "string",
age: "number",
email: "string",
hobbies: ["string"]
};
const results = parseJSON(extremelyBrokenJSON, schema);
console.log(results);
Parses an extremely broken JSON string using the provided schema and returns multiple possible interpretations.
Returns an array of ParseResult objects, each containing a possible interpretation and a confidence score.
An object with the following properties:
true) Enables case-insensitive matching for property names.true) Attempts to match attributes based on best approximation.For scenarios where the JSON is almost unrecognizable, the parser still manages to extract relevant data. Here’s an example:
import { parseJSON } from './llm-json-parser';
const shatteredJSON = `
{
"user": [
"Alice Smith",
28,
{
"email": [
"alice@example.com",
] ,
"phone": "555-1234"
}
],
"orders": [
[1, "Laptop"],
[2, "Mouse and Keyboard"]
]
}
`;
const complexSchema = {
user: {
name: "string",
age: "number",
contact: {
email: "string",
phone: "string"
}
},
orders: [{
id: "number",
product: "string"
}]
};
const results = parseJSON(shatteredJSON, complexSchema);
console.log(results);
Even with broken JSON, LLM JSON Parser will try to extract as much data as possible. Here's how to handle potential errors:
try {
const results = parseJSON(shatteredJSON, schema);
results.forEach((result, index) => {
console.log(`Parse result ${index + 1} (Confidence: ${result.confidence}):`);
console.log(result.data);
});
} catch (error) {
console.error('Parsing failed:', error.message);
// Handle the error appropriately
}
LLM JSON Parser can also detect and recover values that don't adhere to the provided schema, which is particularly useful when large language models (LLMs) hallucinate and embed data under labels you didn't ask for.
For example, if the LLM places an email field under contact.email instead of directly under the root as specified in the schema, the parser can intelligently recover the data and map it to the correct location.
Using heuristic-based matching and schema-guided reconstruction, LLM JSON Parser ensures that misplaced values are placed where they should be according to the intended schema.
Contributions are welcome! Follow these steps to contribute:
git checkout -b feature/AmazingFeature).git commit -m 'Add some AmazingFeature').git push origin feature/AmazingFeature).This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please file an issue on the GitHub repository.
FAQs
LLM JSON Parser is a groundbreaking TypeScript library designed to parse and reconstruct even the most severely broken JSON data using a predefined schema ( useful to parse json output by LLM ). This library pushes the limits of what is possible in JSON p
We found that llm-json-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.