An open API service indexing awesome lists of open source software.

https://github.com/transitive-bullshit/openai-partial-json-parser

Partial JSON parser extracted from OpenAI's vendored version.
https://github.com/transitive-bullshit/openai-partial-json-parser

Last synced: about 1 month ago
JSON representation

Partial JSON parser extracted from OpenAI's vendored version.

Awesome Lists containing this project

README

        

# openai-partial-json-parser

> Partial JSON parser extracted from [OpenAI's vendored version](https://github.com/openai/openai-node/tree/master/src/_vendor).


Build Status
NPM
MIT License
Prettier Code Formatting

- [Intro](#intro)
- [Install](#install)
- [Usage](#usage)
- [Why?](#why)
- [Related](#related)
- [License](#license)

## Intro

This package exports OpenAI's [vendored version of partial-json-parser](https://github.com/openai/openai-node/tree/master/src/_vendor/partial-json-parser) as a standalone module, which itself is a refactored version of the [original npm partial-json-parser](https://www.npmjs.com/package/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).

```sh
npm install openai-partial-json-parser
```

## Usage

```ts
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](https://github.com/dexaai/openai-fetch), [dexter](https://github.com/dexaai/dexter), and [agentic](https://github.com/transitive-bullshit/agentic).

## Related

- [openai-zod-to-json-schema](https://github.com/transitive-bullshit/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](https://x.com/transitive_bs)