flix

0.73.0

Util.Json

enum Json with EqSource
case JArray(Vector[Json])case JBool(Bool)case JNullcase JNumber(BigDecimal)case JObject(Map[String, Json])case JString(String)

Represents a JSON value.

JSON numbers are stored as BigDecimal for lossless round-trip; JSON objects are stored as Map[String, Json], which gives canonical (sorted) key order on output.

Instances

instance Eq[Json]Source
instance FromJson[Json]Source
instance ToJson[Json]Source
instance ToString[Json]Source

Definitions

def decode(s: String): Result[JsonError, a] with FromJson[a] Source

Parses s as a JSON value and decodes it as a via FromJson[a].

Returns Err(Parse(...)) if parsing fails or Err(Decode(...)) if decoding fails.

def parse(s: String): Result[JsonError, Json] Source

Parses s as a JSON value.

Returns Ok(j) if s is a single well-formed JSON value (with optional surrounding whitespace) and nothing else. Returns Err(JsonError) otherwise — see Json.JsonError for the cases.

def toCompactString(j: Json): String Source

Returns the compact JSON rendering of j: a single line with no extraneous whitespace.

def toPrettyString(indent: Int32, j: Json): String Source

Returns the pretty-printed JSON rendering of j, using indent spaces per nesting level.

Empty arrays and objects are rendered on a single line as [] or {}. Non-empty containers place each element on its own line; object keys are followed by ": ".

def toRichString(indent: Int32, j: Json): RichString Source

Returns the pretty-printed JSON rendering of j as a RichString, with syntax-coloured tokens.

The layout is identical to toPrettyString. Colours: null is gray, booleans are magenta, numbers are yellow, string values are green, and object keys are cyan. Punctuation and whitespace use the default colour.