sonic
sonic copied to clipboard
Checking if a field has a certain JSON type
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:
- Call
StringorArrayand check for errors - 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.
Why can ast.Node.Type() not satisfy it?