bytedance / bytedance/sonic

Checking if a field has a certain JSON type

Open
#652 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
9.6k
Forks
474
Avg merge
2d 16h
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start by locating AstNode and its existing String, Array, and Interface methods, then inspect how their errors distinguish JSON types. Done means the requested string and array type checks are supported with performance behavior considered and coverage for the new API.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.