Json

zio.json.ast.Json
See theJson companion object
sealed abstract class Json

This AST of JSON is made available so that arbitrary JSON may be included as part of a business object, it is not used as an intermediate representation, unlike most other JSON libraries. It is not advised to .map or .mapOrFail from these decoders, since a higher performance decoder is often available.

Beware of the potential for DOS attacks, since an attacker can provide much more data than is perhaps needed.

Also beware of converting Num (a BigDecimal) into any other kind of number, since many of the stdlib functions are non-total or are known DOS vectors (e.g. calling .toBigInteger on a "1e214748364" will consume an excessive amount of heap memory). JsonValue / Json / JValue

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Arr
class Bool
object Null.type
class Num
class Obj
class Str
Show all
Self type

Members list

Value members

Concrete methods

final def arrayOrObject[X](or: => X, jsonArray: Chunk[Json] => X, jsonObject: Obj => X): X
final def as[A](implicit decoder: JsonDecoder[A]): Either[String, A]
def asArray: Option[Chunk[Json]]
def asBoolean: Option[Boolean]
def asNull: Option[Unit]
def asNumber: Option[Num]
def asObject: Option[Obj]
def asString: Option[String]
final def delete(cursor: JsonCursor[_, _]): Either[String, Json]

Deletes json node specified by given cursor

Deletes json node specified by given cursor

Value parameters

cursor

Cursor which specifies node to delete

Attributes

Returns

Json without specified node if node specified by cursor exists, error otherwise

final override def equals(that: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
Any
final def foldDown[A](initial: A)(f: (A, Json) => A): A
final def foldDownSome[A](initial: A)(pf: PartialFunction[(A, Json), A]): A
final def foldUp[A](initial: A)(f: (A, Json) => A): A
final def foldUpSome[A](initial: A)(pf: PartialFunction[(A, Json), A]): A
final def get[A <: Json](cursor: JsonCursor[_, A]): Either[String, A]
final override def hashCode: Int

Calculate a hash code value for the object.

Calculate a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Definition Classes
Any
final def intersect(that: Json): Either[String, Json]

Intersects JSON values. If both values are Obj or Arr method returns intersections of its fields/elements, otherwise it returns error

Intersects JSON values. If both values are Obj or Arr method returns intersections of its fields/elements, otherwise it returns error

Attributes

Returns

Intersected json if type are compatible, error otherwise

def mapArray(f: Chunk[Json] => Chunk[Json]): Json
def mapBoolean(f: Boolean => Boolean): Json
def mapObject(f: Obj => Obj): Json
def mapObjectEntries(f: ((String, Json)) => (String, Json)): Json
def mapObjectKeys(f: String => String): Json
def mapString(f: String => String): Json
final def merge(that: Json): Json
  • merging objects results in a new objects with all pairs of both sides, with the right hand side being used on key conflicts

  • merging arrays results in all of the individual elements being merged

  • scalar values will be replaced by the right hand side

Attributes

final def relocate(from: JsonCursor[_, _], to: JsonCursor[_, _]): Either[String, Json]

Relocates Json node from location specified by from cursor to location specified by to cursor.

Relocates Json node from location specified by from cursor to location specified by to cursor.

Value parameters

from

Cursor which specifies node to relocate

to

Cursor which specifies location where to relocate node

Attributes

Returns

Json without specified node if node specified by cursor exists, error otherwise

override def toString(): String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
final def transformAt[A <: Json](cursor: JsonCursor[_, A])(f: A => Json): Either[String, Json]

Transforms json node specified by given cursor

Transforms json node specified by given cursor

Type parameters

A

refined node type

Value parameters

cursor

Cursor which specifies node to transform

f

Function used to transform node

Attributes

Returns

Json with transformed node if node specified by cursor exists, error otherwise

final def transformDown(f: Json => Json): Json
final def transformDownSome(pf: PartialFunction[Json, Json]): Json
final def transformUp(f: Json => Json): Json
final def transformUpSome(pf: PartialFunction[Json, Json]): Json
final def widen: Json