New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jsonfixerai

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonfixerai

Official SDK for the JsonFixer API — AI-powered JSON repair, validation, and schema conversion.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

jsonfixer

npm version npm downloads License: MIT TypeScript

Official SDK for the JsonFixer API — AI-powered JSON repair, validation, and schema conversion in one npm install.

Drop it between your LLM call and your JSON.parse(). Every broken response gets fixed before it reaches your application logic — deterministically, in under 200 ms.

npm install jsonfixer

Quick start

import { fix } from 'jsonfixer';

// Broken LLM output → repaired JSON
const result = await fix('{"name": "Alice", age: 30}', {
  apiKey: 'jf_your_key_here',
});

const parsed = JSON.parse(result.result);
console.log(parsed); // { name: 'Alice', age: 30 }
console.log(result.stage); // 'wasm' | 'jsonrepair' | 'ai' | 'ai-retry'

Get your API key at jsonfixer.ai/dashboard/developer.

Installation

# npm
npm install jsonfixer

# pnpm
pnpm add jsonfixer

# yarn
yarn add jsonfixer

# Deno (import from npm)
import { fix } from 'npm:jsonfixer';

Quick start (plain JavaScript)

No TypeScript required — works with plain Node.js:

// CommonJS (Node.js)
const { fix } = require('jsonfixer');

fix('{"name": "Alice", age: 30}', { apiKey: 'jf_your_key_here' })
  .then(result => console.log(JSON.parse(result.result)))
  .catch(err => console.error(err.message));
// ESM (Node.js 18+, Deno, browser bundler)
import { fix } from 'jsonfixer';

const result = await fix('{"name": "Alice", age: 30}', {
  apiKey: 'jf_your_key_here',
});
console.log(JSON.parse(result.result)); // { name: 'Alice', age: 30 }

Usage

Named export fix()

The quickest way — pass the broken JSON and your API key:

import { fix } from 'jsonfixer';

const result = await fix(brokenJson, { apiKey: 'jf_...' });
const data = JSON.parse(result.result);

Class JsonFixer

Configure once, reuse across your application:

import JsonFixer from 'jsonfixer';

const client = new JsonFixer({
  apiKey: process.env.JSONFIXER_API_KEY!,
  strategy: 'standard', // default
  timeoutMs: 30_000,    // default
});

// Repair raw LLM output
const result = await client.fix(llmResponse);
const parsed = JSON.parse(result.result);

Examples

Node.js — repair LLM output before parsing

import OpenAI from 'openai';
import { fix, JsonFixerError } from 'jsonfixer';

const openai = new OpenAI();
const client = new (await import('jsonfixer')).default({
  apiKey: process.env.JSONFIXER_API_KEY!,
});

const chat = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Return a JSON object with name and age' }],
});

const raw = chat.choices[0].message.content ?? '';

try {
  const fixed = await client.fix(raw);
  const data = JSON.parse(fixed.result);
  console.log('Parsed safely:', data);
} catch (err) {
  if (err instanceof JsonFixerError) {
    console.error('Repair failed:', err.message, '(status:', err.status, ')');
  }
}

Deno — validate config files

import { fix } from 'npm:jsonfixer';

const raw = await Deno.readTextFile('./config.json');

const result = await fix(raw, {
  apiKey: Deno.env.get('JSONFIXER_API_KEY')!,
});

const config = JSON.parse(result.result);
console.log('Loaded config via stage:', result.stage);

Browser (bundler) — validate user input

import { fix } from 'jsonfixer';

async function validateInput(userInput: string) {
  try {
    const result = await fix(userInput, {
      apiKey: import.meta.env.VITE_JSONFIXER_API_KEY,
      timeoutMs: 10_000,
    });
    return JSON.parse(result.result);
  } catch {
    return null; // invalid and unrepairable
  }
}

Recursive strategy — deep repair for severely broken output

const result = await fix(badLlmJson, {
  apiKey: 'jf_...',
  strategy: 'recursive', // deeper, slower — best for severely broken input
});

Schema conversion — get TypeScript types back

const result = await fix('{"name": "Alice", "age": 30}', {
  apiKey: 'jf_...',
  schemaTarget: 'typescript', // 'typescript' | 'zod' | 'pydantic' | 'go'
});

console.log(result.result);
// interface Root {
//   name: string;
//   age: number;
// }

API reference

fix(json, options)

function fix(json: string, options: FixOptions): Promise<FixResult>
ParameterTypeRequiredDescription
jsonstringThe malformed JSON string to repair
options.apiKeystringYour jf_ prefixed API key
options.strategy'standard' | 'recursive'Repair depth. Default: 'standard'
options.schemaTarget'typescript' | 'zod' | 'pydantic' | 'go'Return a schema instead of JSON
options.timeoutMsnumberRequest timeout ms. Default: 30000
options.baseUrlstringOverride API URL. Default: https://jsonfixer.ai

new JsonFixer(options)

const client = new JsonFixer(options: JsonFixerOptions);
await client.fix(json: string, overrides?: Omit<FixOptions, 'apiKey'>): Promise<FixResult>
OptionTypeRequiredDescription
apiKeystringYour jf_ prefixed API key
strategy'standard' | 'recursive'Default strategy for this instance
timeoutMsnumberDefault timeout for this instance
baseUrlstringOverride base URL

FixResult

interface FixResult {
  success: true;
  result: string;       // Repaired JSON — pass to JSON.parse()
  stage: RepairStage;   // 'wasm' | 'jsonrepair' | 'ai' | 'ai-retry'
  inputLength: number;  // Input size in bytes
  outputLength: number; // Output size in bytes
}

JsonFixerError

Thrown on any API error, network failure, or timeout.

class JsonFixerError extends Error {
  status: number;        // HTTP status, or 0 for network/timeout errors
  code: string | undefined; // Short error code: 'TIMEOUT', 'NETWORK_ERROR', 'MISSING_API_KEY', etc.
}

The four-stage pipeline

JsonFixer runs your input through up to four increasingly powerful repair stages:

StageTechnologySpeedUse case
wasmCustom WASM heuristics~5 ms90% of real-world cases
jsonrepairjsonrepair~10 msStructural issues
aiAI~150 msComplex/ambiguous malformation
ai-retryAI (second pass)~300 msLast resort

The SDK returns the stage field so you can track which stage fired in your metrics.

Error handling

import { fix, JsonFixerError } from 'jsonfixer';

try {
  const result = await fix(badJson, { apiKey: 'jf_...' });
  return JSON.parse(result.result);
} catch (err) {
  if (err instanceof JsonFixerError) {
    switch (err.code) {
      case 'TIMEOUT':
        console.error('Request timed out');
        break;
      case 'NETWORK_ERROR':
        console.error('Could not reach the API');
        break;
      default:
        console.error(`API error ${err.status}: ${err.message}`);
    }
  }
  throw err;
}

Plans & pricing

PlanPriceAI repairsFile sizeAPI calls
Free trial$01 lifetime50 KB
Pay-per-call$0.002 / reqUnlimited5 MBUnlimited
Pro$12 / mo500 / month5 MB1,000 / day
Team$199 / moUnlimited50 MB50,000 / month

All plans include the full four-stage self-healing pipeline.

Get your API key → jsonfixer.ai/dashboard/developer

Publishing

This package is ready to publish. Run:

cd packages/jsonfixer-sdk
npm install
npm run build
npm publish --access public

Make sure you're logged into npm (npm login) and own the jsonfixer package name.

License

MIT © JsonFixer

Keywords

json

FAQs

Package last updated on 21 Mar 2026

Did you know?

Socket

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.

Install

Related posts