-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add methods for querying JSON values
This adds the type std.json.Query, used for querying JSON values without the usual boilerplate. Take this JSON for example: { "name": "Alice", "address": { "street": "Sesame Street" } } Using the new Query type, we can query the value like so: json_value.query.key('address').key('street').as_string Querying is done using the Query.key and Query.index methods. Obtaining the values as a certain type is done using Query.as_string, Query.as_int, Query.as_float, Query.as_array, and Query.as_object. There's no Query.as_null method as explicitly checking for NULL is basically useless, and one should instead test for what value they _did_ expect (e.g. a string). The query API methods move the Query object they are called on, removing the need for allocating a new Query object for every step in the query. This means the only allocations needed are those for the Option values used as part of the querying process. This fixes #356. Changelog: added
- Loading branch information
1 parent
e287956
commit 7f5bcac
Showing
2 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters