tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
14.1k stars 846 forks source link

pretty full response #231

Open Kur-Ich opened 3 years ago

Kur-Ich commented 3 years ago

Hi, I'm getting as response an array of objects. Is there a way to pretty the whole array or json object? I can't give in a path because I need the whole array directly underneath the object.

Resp: [{"sport":"Greyhound Racing","plan":"Basic Plan","forDate":"2020-01-01T00:00:00","purchaseItemId":65721},{"sport":"Greyhound Racing","plan":"Basic Plan","forDate":"2020-02-01T00:00:00","purchaseItemId":65721},...]

I tried: js := gjson.GetBytes(bs, "|@pretty")

Thanks

Kur-Ich commented 3 years ago

Solved it like this:

jss := gjson.ParseBytes(resp) for _, js := range jss.Array() { println(js.String()) }