/ Path separator.
name Matches field "name".
a,b,c Matches fields "a", "b", or "c".
* Matches one object, array, or field.
** Matches zero or more objects, arrays, or fields.
(name) Captures field "name".
(a),b,(c,d) Captures multiple fields.
(*) or (**) Captures wildcard matches.
@ after a match to control when processors receive captured values.
devices/(id,name) Without @ values are processed once at the end and only the first values matched are
captured.
devices/(id@,name@) Process "id" and "name" as soon as each is captured.
devices/(id,name)@ Same as (id@,name@).
devices@/(id,name) Process "id" and "name" as a pair for each device.
*@/(id,name) Any match can be annotated to process.
**@/(id,name) All captures after **@ are processed as soon as each is captured.
data/(items) with {data:{items:[1,2,3]}} gives: {items=[1,2,3]}
[] in a capture to collect into an array rather than as a single value.
*/(id) with {first:{id:1},second:{id:2}} gives: {id=1} (parsing ends after first
match)
*/(id[]) gives: {id=[1, 2]} (all matches collected in an array)
{users:[{name:nate},{name:iva}]}users@/(name)
users matches the users:[ array. The field name and value are matched together.
@ processes captured values at the end of each array item.
(name) captures the "name" field and value.
nate and again with iva.
{config:{port:8081}}
Get the first port from "config" found at any depth: **/config/(port)
Result: Processors are called with: 8081
{services:[{status:up},{status:down},{status:failed}]}
Get all service statuses in an array: services/*/(status[])
Result: Processors are called with: [up, down, failed]
{items:[{id:123,type:cookies},{id:456,type:cake}]}
Process each "id" and "type" pair: items@/(id,type)
Result: Since there are multiple captures, processors are called with an object: {id=123,type=cookies} and
{id=456,type=cake}
/,*@()[]',\ by surrounding them with single quotes.
email/'moo@dog.com' Uses "[email protected]" as a literal string.
words/'can''t' Escape single quote with two single quotes.
().
object/() with {object:{a:1,b:2,c:3}} gives: a (parsing ends after first match)
object/()[] gives: [a,b,c] (all keys collected in an array)
reject() prevents further matching at this level or deeper, useful for filtering. A pattern can reject a different
pattern.
clear() discards unprocessed captured values.
parseValue() returns captures at the end of parsing for convenience rather than using a processor.
parseStart() and parseEnd() can be overidden to take action before or after parsing.
end() prevents further matching and ends parsing. stop() does the same but also clears.
*@, **@, or [] parsing ends once all specified values are captured.
"" pattern captures the entire JSON document.
@ processing, references should not be kept.
JsonValue#asFloat()).
process() or a processor to handle captures one by one. Use parseValue() to
obtain captures directly:
JsonValue values = matcher.parseValue(json);
String error = value.getString("message", null);
if (error != null) fail(error);
return value.getString("access_token");
If an anonymous class processes values, var provides access to the fields (Java 10+):
var matcher = new JsonMatcher("(message,access_token)") {
String error, accessToken;
protected void process (JsonValue value) {
error = value.getString("message", null);
accessToken = value.getString("access_token");
}
};
matcher.parse(json);
if (matcher.error != null) fail(matcher.error);
return matcher.accessToken;
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| public static interface |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv JsonMatcher. | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv int | |
| pack-priv char[] | |
| private static final boolean | |
| pack-priv int | |
| pack-priv int | |
| pack-priv static final int | |
| pack-priv static final int | |
| private static final int | |
| pack-priv JsonMatcher. | |
| pack-priv final IntArray | |
| pack-priv JsonMatcher. | |
| pack-priv static final int | |
| pack-priv JsonMatcher. | |
| pack-priv JsonMatcher. | |
| private boolean | |
| pack-priv static final int | |
| pack-priv boolean | |
| pack-priv int |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | |
| public int | Returns: The new pattern's index.Adds a pattern for value extraction. |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| public void | |
| public void | |
| public void | |
| private void | |
| public int | |
| public void | |
| pack-priv JsonMatcher. | |
| pack-priv JsonMatcher. | newNode(JsonMatcher.
|
| pack-priv JsonMatcher. | |
| public String | |
| public String | parent(int up)
Returns the segment of the JSON path up the specified segments from the end, starting at 0, or "" if there aren't enough segments. |
| public void | |
| protected void | |
| protected void | |
| public JsonValue | |
| public JsonValue | |
| public JsonValue | |
| public JsonValue | |
| public JsonValue | |
| public String | |
| public int | |
| protected void | pop()
Overrides com. Called when the end of an object or array is encountered in the JSON. |
| private void | |
| protected void | |
| protected void | push(JsonSkimmer.
Overrides com. Called when an object or array is encountered in the JSON. |
| public void | |
| public void | |
| public void | |
| public void | setProcessor(JsonMatcher.
This processor is invoked for all pattern matches, after per pattern processors and before |
| public void | stop()
Overrides com. Causes parsing to stop as soon as possible, without any further processing. |
| protected void | value(JsonSkimmer.
Overrides com. Called when a value is encountered in the JSON. |
| private JsonValue |
| all | back to summary |
|---|---|
| pack-priv JsonMatcher. | |
| array | back to summary |
|---|---|
| pack-priv static final int array | |
| capture | back to summary |
|---|---|
| pack-priv static final int capture | |
| captured | back to summary |
|---|---|
| pack-priv int captured | |
| chars | back to summary |
|---|---|
| pack-priv char[] chars | |
| debug | back to summary |
|---|---|
| private static final boolean debug | |
| depth | back to summary |
|---|---|
| pack-priv int depth | |
| endCaptures | back to summary |
|---|---|
| pack-priv int endCaptures | |
| keys | back to summary |
|---|---|
| pack-priv static final int keys | |
| match | back to summary |
|---|---|
| pack-priv static final int match | |
| none | back to summary |
|---|---|
| private static final int none | |
| original | back to summary |
|---|---|
| pack-priv JsonMatcher. | |
| path | back to summary |
|---|---|
| pack-priv final IntArray path | |
| patterns | back to summary |
|---|---|
| pack-priv JsonMatcher. | |
| process | back to summary |
|---|---|
| pack-priv static final int process | |
| processor | back to summary |
|---|---|
| pack-priv JsonMatcher. | |
| processPattern | back to summary |
|---|---|
| pack-priv JsonMatcher. | |
| rejected | back to summary |
|---|---|
| private boolean rejected | |
| single | back to summary |
|---|---|
| pack-priv static final int single | |
| stoppable | back to summary |
|---|---|
| pack-priv boolean stoppable | |
| total | back to summary |
|---|---|
| pack-priv int total | |
| JsonMatcher | back to summary |
|---|---|
| public JsonMatcher() | |
| JsonMatcher | back to summary |
|---|---|
| public JsonMatcher(String... patterns) Adds all of the specified patterns. | |
| addPattern | back to summary |
|---|---|
| public int addPattern(String pattern) Adds a pattern for value extraction.
| |
| addPattern | back to summary |
|---|---|
| public int addPattern(String pattern, JsonMatcher. Adds a pattern for value extraction. The processor is invoked only for this pattern's matches.
| |
| captureAllStart | back to summary |
|---|---|
| private void captureAllStart(JsonMatcher. | |
| captureAllValue | back to summary |
|---|---|
| private void captureAllValue(JsonMatcher. | |
| captured | back to summary |
|---|---|
| private void captured(JsonMatcher. | |
| captureRoot | back to summary |
|---|---|
| private void captureRoot() If there are no patterns, set a temporary pattern to capture the root. | |
| captureValue | back to summary |
|---|---|
| private void captureValue(JsonMatcher. | |
| clear | back to summary |
|---|---|
| public void clear() Clears any captured values for the current pattern. Only valid during processing. | |
| clear | back to summary |
|---|---|
| public void clear(int patternIndex) Clears any captured values for the specified pattern. Only valid during processing. | |
| clearAll | back to summary |
|---|---|
| public void clearAll() Clears any captured values for all patterns. Only valid during processing. | |
| debug | back to summary |
|---|---|
| private void debug(JsonMatcher. | |
| depth | back to summary |
|---|---|
| public int depth() 0 when not processing. | |
| end | back to summary |
|---|---|
| public void end() Causes parsing to stop as soon as possible, processing any values already collected. | |
| newMatch | back to summary |
|---|---|
pack-priv JsonMatcher.
| |
| newNode | back to summary |
|---|---|
pack-priv JsonMatcher.
| |
| newPattern | back to summary |
|---|---|
pack-priv JsonMatcher.
| |
| parent | back to summary |
|---|---|
| public String parent() Returns the last segment of the JSON path. "" when not processing.
| |
| parent | back to summary |
|---|---|
| public String parent(int up) Returns the segment of the JSON path up the specified segments from the end, starting at 0, or "" if there aren't enough segments. "" when not processing.
| |
| parse | back to summary |
|---|---|
| public void parse(char[] data, int offset, int length) Overrides com.
| |
| parseEnd | back to summary |
|---|---|
| protected void parseEnd() Called just after parsing finishes. | |
| parseStart | back to summary |
|---|---|
| protected void parseStart() Called just before parsing begins. | |
| parseValue | back to summary |
|---|---|
| public JsonValue parseValue(char[] data, int offset, int length) Parses and returns captures for patterns without | |
| parseValue | back to summary |
|---|---|
| public JsonValue parseValue(String json) Parses and returns captures for patterns without | |
| parseValue | back to summary |
|---|---|
| public JsonValue parseValue(Reader reader) Parses and returns captures for patterns without | |
| parseValue | back to summary |
|---|---|
| public JsonValue parseValue(InputStream input) Parses and returns captures for patterns without | |
| parseValue | back to summary |
|---|---|
| public JsonValue parseValue(FileHandle file) Parses and returns captures for patterns without | |
| path | back to summary |
|---|---|
| public String path() Returns the current JSON path using "/" as separator. Anonymous objects use "{}", arrays "[]". "" when not processing. | |
| pattern | back to summary |
|---|---|
| public int pattern() Returns the index of the pattern currently being processed. -1 when not processing. | |
| pop | back to summary |
|---|---|
| protected void pop() Overrides com. Doc from com. Called when the end of an object or array is encountered in the JSON.
| |
| process | back to summary |
|---|---|
| private void process(JsonMatcher. | |
| process | back to summary |
|---|---|
| protected void process(JsonValue value) Called for all pattern matches, after any processors have been invoked. | |
| push | back to summary |
|---|---|
| protected void push(JsonSkimmer. Overrides com. Doc from com. Called when an object or array is encountered in the JSON.
| |
| reject | back to summary |
|---|---|
| public void reject() Rejects the current pattern. Only valid during processing.
| |
| reject | back to summary |
|---|---|
| public void reject(int patternIndex) Rejects a specific pattern. Only valid during processing.
| |
| rejectAll | back to summary |
|---|---|
| public void rejectAll() Prevents further matching of any pattern at the current level or deeper. Matching resumes when parsing returns to a higher level. Only valid during processing. | |
| setProcessor | back to summary |
|---|---|
| public void setProcessor(JsonMatcher. This processor is invoked for all pattern matches, after per pattern processors and before | |
| stop | back to summary |
|---|---|
| public void stop() Overrides com. Causes parsing to stop as soon as possible, without any further processing.
| |
| value | back to summary |
|---|---|
| protected void value(JsonSkimmer. Overrides com. Doc from com. Called when a value is encountered in the JSON.
| |
| valueStart | back to summary |
|---|---|
| private JsonValue valueStart() | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final boolean | |
| pack-priv int | |
| pack-priv final String | |
| pack-priv final boolean | |
| pack-priv final boolean |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| public String |
| any | back to summary |
|---|---|
| pack-priv final boolean any | |
| flags | back to summary |
|---|---|
| pack-priv int flags | |
| name | back to summary |
|---|---|
| pack-priv final String name | |
| star | back to summary |
|---|---|
| pack-priv final boolean star | |
| starStar | back to summary |
|---|---|
| pack-priv final boolean starStar | |
| Match | back to summary |
|---|---|
| pack-priv Match(String name, int flags, boolean star, boolean starStar) | |
| toString | back to summary |
|---|---|
| pack-priv void toString(StringBuilder buffer) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv JsonMatcher. | |
| pack-priv int | |
| pack-priv final JsonMatcher. | |
| pack-priv JsonMatcher. | |
| pack-priv boolean | |
| pack-priv int | |
| pack-priv JsonMatcher. | |
| pack-priv final boolean | |
| pack-priv boolean | |
| pack-priv boolean |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv int | |
| private void | |
| public String |
| backtrack | back to summary |
|---|---|
| pack-priv JsonMatcher. | |
| dead | back to summary |
|---|---|
| pack-priv int dead | |
| matches | back to summary |
|---|---|
| pack-priv final JsonMatcher. | |
| next | back to summary |
|---|---|
| pack-priv JsonMatcher. | |
| nextStarStar | back to summary |
|---|---|
| pack-priv boolean nextStarStar | |
| pop | back to summary |
|---|---|
| pack-priv int pop | |
| prev | back to summary |
|---|---|
| pack-priv JsonMatcher. | |
| processEach | back to summary |
|---|---|
| pack-priv final boolean processEach | |
| processPop | back to summary |
|---|---|
| pack-priv boolean processPop | |
| starStar | back to summary |
|---|---|
| pack-priv boolean starStar | |
| Node | back to summary |
|---|---|
| pack-priv Node(JsonMatcher. | |
| match | back to summary |
|---|---|
| pack-priv int match(JsonSkimmer. | |
| toString | back to summary |
|---|---|
| private void toString(StringBuilder buffer) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv boolean | |
| pack-priv JsonValue | |
| pack-priv boolean | |
| pack-priv int | |
| pack-priv boolean | |
| pack-priv JsonMatcher. | |
| pack-priv final JsonMatcher. | |
| pack-priv final JsonMatcher. | |
| pack-priv final Array | |
| pack-priv int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void | |
| public String |
| at | back to summary |
|---|---|
| pack-priv boolean at | |
| capture | back to summary |
|---|---|
| pack-priv JsonValue capture | |
| captureAll | back to summary |
|---|---|
| pack-priv boolean captureAll | |
| captured | back to summary |
|---|---|
| pack-priv int captured | |
| captureRoot | back to summary |
|---|---|
| pack-priv boolean captureRoot | |
| current | back to summary |
|---|---|
| pack-priv JsonMatcher. | |
| processor | back to summary |
|---|---|
| pack-priv final JsonMatcher. | |
| root | back to summary |
|---|---|
| pack-priv final JsonMatcher. | |
| stack | back to summary |
|---|---|
| pack-priv final Array<JsonValue> stack | |
| total | back to summary |
|---|---|
| pack-priv int total | |
| Pattern | back to summary |
|---|---|
| pack-priv Pattern(JsonMatcher. | |
| clearCapture | back to summary |
|---|---|
| pack-priv void clearCapture() | |
| reset | back to summary |
|---|---|
| pack-priv void reset() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| process | back to summary |
|---|---|
| public void process(JsonValue value) Called with captured values.
| |