partial-json-parser-js
partial-json-parser-js copied to clipboard
handling of markdown json
sometimes openai returns ```json { "key": "value" } ``` does this lib handles this use case ?
Nope. But there are two workarounds:
- Use json mode.
- Detect JSON boundary using regex like
```json\n(.+?)(?:\n```|`{0,3}\Z)
ok thanks you, nice lib btw. was gonna implement it myself and thought someone must have had the idea already
You can find the first { symbol and the last } in the response. If } is not found or does not match {, then you can determine that the JSON is partial and can be handled by this library.