tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
14.34k stars 854 forks source link

gjson.Valid(str) #371

Open wujiang41105631 opened 1 month ago

wujiang41105631 commented 1 month ago

When I was using the method gjson.Valid(str), I found that if str is a string of pure numbers, for example, str := "123123123", the return result of this method is also true. img_v3_02fj_0f5d5893-7f1e-44be-bc04-953d0f5c0ceg

baxiry commented 1 month ago

All JSON data types are valid, even strings.

"123" is valid because JSON accepts it as {"age": 123}. gjson.Valid removes the quotation marks. However, "adam" is not valid because JSON does not accept something like {"name": adam}; It should be wrapped with quotation marks like: "\"adam\"" to become valid.

examples: 123, is valid as number null, is valid as null "hello", valid as string "123" valid as string true, valid as boolean false, vald "true" valid as string "false" valid as string

but

hello, invalid, should wrap by quotation