Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gjson.Valid(str) #371

Open
wujiang41105631 opened this issue Oct 12, 2024 · 1 comment
Open

gjson.Valid(str) #371

wujiang41105631 opened this issue Oct 12, 2024 · 1 comment

Comments

@wujiang41105631
Copy link

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
Copy link
Contributor

baxiry commented Oct 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants