valyala / fastjson

Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection
MIT License
2.3k stars 138 forks source link

How to avoid string field escape? #70

Closed nuzar closed 3 years ago

nuzar commented 3 years ago

If we get a string field, the result string is escaped (with double quotes).

func main() {
    var data = `{
        "a": "str",
        "b": 1,
        "c": [1,2,3.333333],
        "d": {
            "1": 1,
            "2": 2
        }
    }`

    v, err := fastjson.Parse(data)
    if err != nil {
        log.Fatal(err)
    }

    log.Printf("a: '%s'", v.Get("a"))
}

2021/07/20 12:15:25 a: '"str"'

How to avoid this behavior, to get an exactly "str" string?

nuzar commented 3 years ago

use v.GetStringBytes("a")