json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.41k stars 1.03k forks source link

json.MarshalIndnet doesn't pretty print correctly from json lines #331

Open berglh opened 5 years ago

berglh commented 5 years ago

I'm decoding byte blobs of JSON lines with json.Decoder and trying to pretty print with json.MarshalIndent. The std library produces the expected output, but jsoniter outputs this:

{
    "_source": {
    "@timestamp": "2018-10-07T15:01:48.442Z",
    "source": {
    "geoip": {
    "city_name": "Mosman",
    "country_name": "Australia",
    "location": {
    "lat": -33.839,
    "lon": 151.2396
},
    "region_code": "NSW"
}
},
    "user": {
    "service": "wOot",
    "uid": "1"
}
}
}
{
    "_source": {
    "@timestamp": "2018-10-07T15:01:48.441Z",
    "source": {
    "geoip": {
    "city_name": "Mosman",
    "country_name": "Australia",
    "location": {
    "lat": -33.839,
    "lon": 151.2396
},
    "region_code": "NSW"
}
},
    "user": {
    "service": "wOot",
    "uid": "1"
}
}
}
yifan-gu commented 5 years ago

+1

mjnovice commented 4 years ago

+1

AllenX2018 commented 4 years ago

@mjnovice Could you pls show a complete test case with the definition of your struct to help us to analysis this issue?