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

Checking if a field has a certain JSON type #652

Open
Azmisov opened this issue Jun 16, 2024 · 1 comment
Open

Checking if a field has a certain JSON type #652

Azmisov opened this issue Jun 16, 2024 · 1 comment

Comments

@Azmisov
Copy link

Azmisov commented Jun 16, 2024

I'd like to parse unstructured JSON. For example, a field that is either a string or []string. As a suggestion, I feel there is the need for IsString, IsArray, etc methods. These would theoretically allow checking the type of an AstNode in a performant way. Currently, I am using two techniques to accomplish this, both of which seem poor:

  1. Call String or Array and check for errors
  2. Call Interface, then use reflection to check the type

If an IsString, etc method would be no more performant than either of these techniques, feel free to ignore my suggestion.

@AsterDY
Copy link
Collaborator

AsterDY commented Jun 17, 2024

Why can ast.Node.Type() not satisfy it?

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