openai-partial-json-parser

Partial JSON parser extracted from OpenAI's vendored version.

MIT License

Downloads
143
Stars
13

openai-partial-json-parser

Partial JSON parser extracted from OpenAI's vendored version.

Intro

This package exports OpenAI's vendored version of partial-json-parser as a standalone module, which itself is a refactored version of the original npm partial-json-parser.

It also adds some much-needed unit tests.

This package will be kept in sync with any changes to OpenAI's vendored version.

Install

[!NOTE] This package requires Node.js >= 18 or an equivalent environment (Bun, Deno, CF workers, etc).

npm install openai-partial-json-parser

Usage

import { partialParse } from 'openai-partial-json-parser'

const json = partialParse('{ "foo": true, ')
// { foo: true }

Why?

  • We should be able to access OpenAI's version of partial-json-parser without depending on the entire openai package.
  • OpenAI's vendored version of partial-json-parser doesn't have any unit tests for some reason, which could cause undesired regressions.
  • We wanted a minimal, OpenAI-compatible version of partial-json-parser for openai-fetch, dexter, and agentic.

Related

  • openai-zod-to-json-schema - Same as this module but for OpenAI's vendored zod-to-json-schema with support OpenAI's strict mode for structured outputs.

License

MIT © Travis Fischer