java.lang.Object
net.frozenblock.lib.config.api.instance.xjs.JsonPath
All Implemented Interfaces:
Iterable<com.mojang.datafixers.util.Either<String,Integer>>

public class JsonPath extends Object implements Iterable<com.mojang.datafixers.util.Either<String,Integer>>
An object representing every accessor in a JSON object leading to a value.

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.

  • Constructor Details

  • Method Details

    • builder

      public static JsonPath.JsonPathBuilder builder()
      Creates a new JSON path builder, used for programmatically generating new JSON path representations.
      Returns:
      A new JsonPath.JsonPathBuilder for constructing JSON paths.
    • stub

      public static JsonPath.Stub stub()
      A lightweight, immutable alternative to JsonPath.JsonPathBuilder, specifically intended for tracking paths over time in scenarios where an actual JsonPath may 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 proper JsonPath, 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 of parse(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

      public static JsonPath objectOnly(String raw)
      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

      public static String serialize(Collection<com.mojang.datafixers.util.Either<String,Integer>> path)
      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

      public static List<JsonPath> getAllPaths(xjs.data.JsonObject json)
      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

      public static List<JsonPath> getUsedPaths(xjs.data.JsonObject json)
      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

      public static List<JsonPath> getUnusedPaths(xjs.data.JsonObject json)
      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

      public Optional<xjs.data.JsonValue> getValue(xjs.data.JsonObject json)
    • setValue

      public void setValue(xjs.data.JsonObject json, @Nullable @Nullable xjs.data.JsonValue value)
    • getClosestMatch

      public JsonPath getClosestMatch(xjs.data.JsonObject json)
    • getLastAvailable

      public int getLastAvailable(xjs.data.JsonObject json)
    • toBuilder

      public JsonPath.JsonPathBuilder toBuilder()
    • beginTracking

      public JsonPath.Stub beginTracking()
    • asCollection

      public Collection<com.mojang.datafixers.util.Either<String,Integer>> asCollection()
    • asRawPath

      public String asRawPath()
    • isEmpty

      public boolean isEmpty()
    • size

      public int size()
    • get

      public com.mojang.datafixers.util.Either<String,Integer> get(int index)
    • indexOf

      public int indexOf(String key)
    • lastIndexOf

      public int lastIndexOf(String key)
    • subList

      public List<com.mojang.datafixers.util.Either<String,Integer>> subList(int s, int e)
    • subPath

      public JsonPath subPath(String key)
    • subPath

      public JsonPath subPath(int s, int e)
    • append

      public JsonPath append(JsonPath path)
    • append

      public JsonPath append(JsonPath path, int startInclusive)
    • append

      public JsonPath append(JsonPath path, int startInclusive, int endExclusive)
    • iterator

      @NotNull public @NotNull Iterator<com.mojang.datafixers.util.Either<String,Integer>> iterator()
      Specified by:
      iterator in interface Iterable<com.mojang.datafixers.util.Either<String,Integer>>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object