tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
14.39k stars 857 forks source link

What is the difference between raw and str #330

Closed 15083787153 closed 1 year ago

15083787153 commented 1 year ago
type Result struct {
    // Type is the json type
    Type Type
    // Raw is the raw json
    Raw string
    // Str is the json string
    Str string
    // Num is the json number
    Num float64
    // Index of raw value in original json, zero means index unknown
    Index int
    // Indexes of all the elements that match on a path containing the '#'
    // query character.
    Indexes []int
}

Is my understanding correct? raw is a native string, and str is a string without escape characters.

tidwall commented 1 year ago

Raw is the raw json. Str is the parsed string value as a Go string

For example, the JSON

"Hello\nWorld"

Raw ==

"Hello\nWorld"

Str ==

Hello
World

I recommend using the String() method instead of Str.