Class JsonPath
In other words, this object is a container holding keys and indices which point to a value at some arbitrary depth in a JSON array or object.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder used for manually constructing JSON paths in-code.static classA lightweight, immutable builder designed for appending paths over time, wherein the more expensiveJsonPathis typically unneeded. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCollection<com.mojang.datafixers.util.Either<String, Integer>> static JsonPath.JsonPathBuilderbuilder()Creates a new JSON path builder, used for programmatically generating new JSON path representations.booleanget(int index) getAllPaths(xjs.data.JsonObject json) Generates a list of every possible JSON path in this object.getClosestMatch(xjs.data.JsonObject json) intgetLastAvailable(xjs.data.JsonObject json) xjs.data.JsonContainergetLastContainer(xjs.data.JsonObject json) getUnusedPaths(xjs.data.JsonObject json) Generates a list of every unused JSON path in this object.getUsedPaths(xjs.data.JsonObject json) Generates a list of every used JSON path in this object.Optional<xjs.data.JsonValue> getValue(xjs.data.JsonObject json) inthashCode()intbooleanisEmpty()iterator()intlastIndexOf(String key) static JsonPathobjectOnly(String raw) Generates a new JsonPath from a string containing only keys.static JsonPathparse(com.mojang.brigadier.StringReader reader) Deserializes the given raw path into a collection of keys and indices.static JsonPathDeserializes the given raw path into a collection of keys and indices.static Stringserialize(Collection<com.mojang.datafixers.util.Either<String, Integer>> path) Converts the given JSON path data into a raw string.voidsetValue(xjs.data.JsonObject json, @Nullable xjs.data.JsonValue value) intsize()static JsonPath.Stubstub()A lightweight, immutable alternative toJsonPath.JsonPathBuilder, specifically intended for tracking paths over time in scenarios where an actualJsonPathmay not be needed.subList(int s, int e) subPath(int s, int e) toString()static personthecat.fresult.Result<JsonPath, com.mojang.brigadier.exceptions.CommandSyntaxException> Variant ofparse(String)which returns instead of throwing an exception.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
JsonPath
-
JsonPath
-
-
Method Details
-
builder
Creates a new JSON path builder, used for programmatically generating new JSON path representations.- Returns:
- A new
JsonPath.JsonPathBuilderfor constructing JSON paths.
-
stub
A lightweight, immutable alternative toJsonPath.JsonPathBuilder, specifically intended for tracking paths over time in scenarios where an actualJsonPathmay not be needed.For example, an application performing analysis on a body of JSON data might "track" the current path using one of these objects. If for some reason a specific path needs to be saved, the dev might call
JsonPath.Stub.capture()to generate a properJsonPath, which can be reflected on at a later time.This is equivalent to using a regular
JsonPath.JsonPathBuilder, while being modestly less expensive in that context. However, because it is immutable, it may be repeatedly passed into various other methods without the threat of any accidental mutations further down the stack.- Returns:
JsonPath.Stub.EMPTY, for building raw JSON paths.
-
parse
public static JsonPath parse(String raw) throws com.mojang.brigadier.exceptions.CommandSyntaxException Deserializes the given raw path into a collection of keys and indices.- Parameters:
raw- The raw JSON path being deserialized.- Returns:
- An object representing every accessor leading to a JSON value.
- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- If the path is formatted incorrectly.
-
parse
public static JsonPath parse(com.mojang.brigadier.StringReader reader) throws com.mojang.brigadier.exceptions.CommandSyntaxException Deserializes the given raw path into a collection of keys and indices.- Parameters:
reader- A reader exposing the raw JSON path being deserialized.- Returns:
- An object representing every accessor leading to a JSON value.
- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- If the path is formatted incorrectly.
-
tryParse
public static personthecat.fresult.Result<JsonPath,com.mojang.brigadier.exceptions.CommandSyntaxException> tryParse(String raw) Variant ofparse(String)which returns instead of throwing an exception.- Parameters:
raw- The raw JSON path being deserialized.- Returns:
- An object representing every accessor leading to a JSON value.
-
objectOnly
Generates a new JsonPath from a string containing only keys.This method is intended as optimization in cases where no arrays are needed.
- Parameters:
raw- The raw JSON path containing keys only.- Returns:
- A new object representing this path.
-
serialize
Converts the given JSON path data into a raw string.- Parameters:
path- The parsed JSON path being serialized.- Returns:
- A string representing the equivalent path.
-
getAllPaths
Generates a list of every possible JSON path in this object.- Parameters:
json- The json containing the expected paths.- Returns:
- A list of objects representing these paths.
-
getUsedPaths
Generates a list of every used JSON path in this object.- Parameters:
json- The json containing the expected paths.- Returns:
- A list of objects representing these paths.
-
getUnusedPaths
Generates a list of every unused JSON path in this object.- Parameters:
json- The json containing the expected paths.- Returns:
- A list of objects representing these paths.
-
getLastContainer
public xjs.data.JsonContainer getLastContainer(xjs.data.JsonObject json) -
getValue
-
setValue
public void setValue(xjs.data.JsonObject json, @Nullable @Nullable xjs.data.JsonValue value) -
getClosestMatch
-
getLastAvailable
public int getLastAvailable(xjs.data.JsonObject json) -
toBuilder
-
beginTracking
-
asCollection
-
asRawPath
-
isEmpty
public boolean isEmpty() -
size
public int size() -
get
-
indexOf
-
lastIndexOf
-
subList
-
subPath
-
subPath
-
append
-
append
-
append
-
iterator
-
equals
-
hashCode
public int hashCode() -
toString
-