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.
- Host: GitHub
- URL: https://github.com/transitive-bullshit/openai-partial-json-parser
- Owner: transitive-bullshit
- License: mit
- Created: 2024-08-07T06:07:55.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-10-16T08:02:27.000Z (8 months ago)
- Last Synced: 2025-03-30T11:11:59.180Z (2 months ago)
- Language: TypeScript
- Size: 285 KB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
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).
- [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)