Class Json

java.lang.Object
io.github.jbastgen.stemma.app.ai.Json

public final class Json extends Object
A small JSON reader and writer, enough for the requests and answers of AI services: objects become Map<String,Object>, arrays List<Object>, numbers Double, plus String, Boolean and null. No dependency, and strict about what it reads.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    The text is not valid JSON.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    parse(String text)
    Reads JSON into maps, lists, strings, doubles, booleans and null; anything after the value is an error.
    static Object
    path(Object root, String path)
    The value at a path of keys and indexes separated by dots, for example choices.0.message.content; or null if there is none.
    static String
    The JSON string literal for s, with the quotes.
    static String
    write(Object value)
    Writes a value built from maps, lists, strings, numbers, booleans and null.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parse

      public static Object parse(String text)
      Reads JSON into maps, lists, strings, doubles, booleans and null; anything after the value is an error.
      Throws:
      Json.JsonException - when the text is not valid JSON
    • quote

      public static String quote(String s)
      The JSON string literal for s, with the quotes.
    • write

      public static String write(Object value)
      Writes a value built from maps, lists, strings, numbers, booleans and null.
    • path

      public static Object path(Object root, String path)
      The value at a path of keys and indexes separated by dots, for example choices.0.message.content; or null if there is none.