tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
13.88k stars 841 forks source link

@fromstr doesn't appear to work #356

Closed lsh-0 closed 2 months ago

lsh-0 commented 2 months ago

Using https://gjson.dev, an input of:

name.last

yields

"Anderson"

and I would expect using the modifier @fromstr like:

name.last|@fromstr

to yield:

Anderson

(without quotes), instead nothing is displayed.

Locally the extracted_value.Exists() is returning false.

Am I using @fromstr correctly? I've also tried some.path.@fromstr as well downgrading to gjson@1.16.0 with the same results.

Thanks,

tidwall commented 2 months ago

The @fromstr modifier is used to unescape json that is stored in a string.

Using the path person.@fromstr.last with json

{"person":"{\"last\":\"Anderson\"}"}

returns "Anderson".

lsh-0 commented 2 months ago

ah ... so is there an equivalent to jq --raw-output that would let me get at the string Anderson without quotes?

tidwall commented 2 months ago
gjson.Get("name.last").String()
lsh-0 commented 2 months ago

Unfortunately the path is passed in by the user, much like https://gjson.dev

@fromstr: Converts a string from json. Unwraps a json string.

It sounds like what I need but I was mistaken. Thanks for your time.

tidwall commented 2 months ago

No problem, glad you found a solution.