json_query library
Extract and map fields from deeply nested JSON into Dart models without writing repetitive manual traversal code.
Classes
- CompiledQuery
-
A
projectionparsed once and reusable across many JSON payloads, avoiding repeated path parsing for queries executed in a loop or on a hot path. - FieldSegment
-
.name— read a field from a Map. - IndexSegment
-
[n]— read an index from a List. - JsonQuery
-
Wraps a decoded JSON value (
Map,List, or anydynamic) and lets you pull out exactly the fields you need using small jq-inspired path strings, optionally mapping the result straight into a Dart object. - PathSegment
-
One step in a parsed query path. A path string is parsed directly into
a
List<PathSegment>— that list is the compiled query, there is no separate AST/compiler stage. - WildcardSegment
-
[]— apply the remaining segments to every element of a List.
Functions
-
parsePath(
String path) → List< PathSegment> -
Parses a jq-inspired path string (e.g.
.data.user.id,.data.users[0],.data.users[]) into a list of PathSegments by walking characters directly — no regex, no intermediate string splitting.
Exceptions / Errors
- JsonQueryAccessException
-
A path was well-formed but could not be resolved against the given JSON
while
required: truewas set (wrong type at a segment, missing field, index out of range). - JsonQueryException
-
Base type for all exceptions thrown by
json_query. - JsonQuerySyntaxException
- A query path string could not be parsed (bad syntax, empty segment, invalid array index, etc).