promplate / partial-json-parser-js

Parse partial JSON generated by LLM
https://npmjs.com/partial-json
MIT License
76 stars 2 forks source link

The parser failed to parse this JSON #1

Closed oney closed 10 months ago

oney commented 10 months ago

Thanks for making this package! It's very useful.

I encounter an issue. My LLM generates this weird but valid JSON string

[
{
"yy": {
"message": "yy"
                                            ,
"yy": "yy"
}
},
{
"xx": {
"xx": "xx"
}
}]

Native JSON.parse(str) can parse it successfully with

[{"yy":{"message":"yy","yy":"yy"}},{"xx":{"xx":"xx"}}]

But import { parse } from "partial-json"; parse(str); output

[{"yy":{"message":"yy"}}]

Could you help me?

CNSeniorious000 commented 10 months ago

Thanks a lot for providing this! I will take a look

CNSeniorious000 commented 10 months ago

I see. Looks like I forgot \t is a valid space char in JSON. I will make a new release solving this soon.


A minimal reproducible is:

> parse(`{"a"\t:""}`)
{}
> JSON.parse(`{"a"\t:""}`)
{ a: '' }
CNSeniorious000 commented 10 months ago

Fixed this in 0.1.4. Thank you again for trying this package and providing valuable bug.

oney commented 9 months ago

That's fast 🤯 Thank you so much for the quick fix!

oney commented 9 months ago

Working great, but index.d.ts file is missing https://www.npmjs.com/package/partial-json/v/0.1.4?activeTab=code

CNSeniorious000 commented 9 months ago

Sorry about that, I personally am not familiar with JavaScript packaging so I made a few mistake. I am working on it now

CNSeniorious000 commented 9 months ago

Fine. I've released v0.1.5 solving this. Thank you a lot for reporting this!