buger / jsonparser

One of the fastest alternative JSON parser for Go that does not require schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsonparser.Delete doesn't handle line breaks comma

Houlton opened this issue · comments

Hi,

data := []byte({
"key1": "v1"
,
"key2": "v2"
}`)

newData := jsonparser.Delete(data, "key1")
fmt.Println(string(newData))

`

In the output, an extra comma exists, which is not a valid json.
{
,
"key2", "v2"
}

Hi,
Please anyone answer this issue?

commented

@Houlton I didn't reproduce your issue.
image

@AllenX2018 that is because you aren't using new lines.
https://play.golang.org/p/DD67y0rgT0r

You need to compact the json first: https://play.golang.org/p/YL4fD0KxFHU

It would be great if this lib could support a in-place compacter.