JsonParser

grapple.json.JsonParser
See theJsonParser companion object
trait JsonParser extends Iterator[Event], AutoCloseable

Defines JSON parser.

import scala.language.implicitConversions

import grapple.json.{ *, given }
import grapple.json.JsonParser.Event

val parser = JsonParser("""{ "id": 1000, "name": "lupita", "groups": ["lupita", "admin"] }""")

try
 // Get first event (start root object)
 assert { parser.next() == Event.StartObject }

 // Get key and value
 assert { parser.next() == Event.Key("id") }
 assert { parser.next() == Event.Value(1000) }

 // Get key and value
 assert { parser.next() == Event.Key("name") }
 assert { parser.next() == Event.Value("lupita") }

 // Get key and value
 assert { parser.next() == Event.Key("groups") }
 assert { parser.next() == Event.StartArray } // start nested array
 assert { parser.next() == Event.Value("lupita") }
 assert { parser.next() == Event.Value("admin") }
 assert { parser.next() == Event.EndArray }   // end nested array

 // Get final event (end root object)
 assert { parser.next() == Event.EndObject }

 // No more events
 assert { !parser.hasNext }
finally
 parser.close()

Attributes

See also
Companion
object
Graph
Supertypes
trait AutoCloseable
trait Iterator[Event]
trait IterableOnceOps[Event, Iterator, Iterator[Event]]
trait IterableOnce[Event]
class Object
trait Matchable
class Any
Show all

Members list

Type members

Inherited classlikes

class GroupedIterator[B >: A](self: Iterator[B], size: Int, step: Int)

Attributes

Inherited from:
Iterator
Supertypes
class AbstractIterator[Seq[B]]
trait Iterator[Seq[B]]
trait IterableOnceOps[Seq[B], Iterator, Iterator[Seq[B]]]
trait IterableOnce[Seq[B]]
class Object
trait Matchable
class Any
Show all

Value members

Abstract methods

def close(): Unit

Closes parser.

Closes parser.

Attributes

Parses and collects remainder of current JSON array.

Parses and collects remainder of current JSON array.

import scala.language.implicitConversions

import grapple.json.{ Json, JsonParser, given }
import grapple.json.JsonParser.Event

val parser = JsonParser("""[1000, "lupita"]""")

assert { parser.next() == Event.StartArray }
assert { parser.getArray() == Json.arr(1000, "lupita") }

Attributes

Note

Parser must be in array context.

Parses and collects remainder of current JSON object.

Parses and collects remainder of current JSON object.

import scala.language.implicitConversions

import grapple.json.{ Json, JsonParser, given }
import grapple.json.JsonParser.Event

val parser = JsonParser("""{ "id": 1000, "name": "lupita" }""")

assert { parser.next() == Event.StartObject }
assert { parser.getObject() == Json.obj("id" -> 1000, "name" -> "lupita") }

Attributes

Note

Parser must be in object context.

def hasNext: Boolean

Tests for next event.

Tests for next event.

Attributes

def next(): Event

Gets next event.

Gets next event.

Attributes

Inherited methods

final def ++[B >: Event](xs: => IterableOnce[B]): Iterator[B]

Attributes

Inherited from:
Iterator
final def addString(b: StringBuilder): StringBuilder

Attributes

Inherited from:
IterableOnceOps
final def addString(b: StringBuilder, sep: String): StringBuilder

Attributes

Inherited from:
IterableOnceOps
def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder

Attributes

Inherited from:
IterableOnceOps
def buffered: BufferedIterator[A]

Attributes

Inherited from:
Iterator
def collect[B](pf: PartialFunction[Event, B]): Iterator[B]

Attributes

Inherited from:
Iterator
def collectFirst[B](pf: PartialFunction[Event, B]): Option[B]

Attributes

Inherited from:
IterableOnceOps
def concat[B >: Event](xs: => IterableOnce[B]): Iterator[B]

Attributes

Inherited from:
Iterator
def contains(elem: Any): Boolean

Attributes

Inherited from:
Iterator
def copyToArray[B >: Event](xs: Array[B], start: Int, len: Int): Int

Attributes

Inherited from:
IterableOnceOps
def copyToArray[B >: Event](xs: Array[B], start: Int): Int

Attributes

Inherited from:
IterableOnceOps
def copyToArray[B >: Event](xs: Array[B]): Int

Attributes

Inherited from:
IterableOnceOps
def corresponds[B](that: IterableOnce[B])(p: (Event, B) => Boolean): Boolean

Attributes

Inherited from:
IterableOnceOps
def count(p: Event => Boolean): Int

Attributes

Inherited from:
IterableOnceOps
def distinct: Iterator[A]

Attributes

Inherited from:
Iterator
def distinctBy[B](f: Event => B): Iterator[A]

Attributes

Inherited from:
Iterator
def drop(n: Int): Iterator[A]

Attributes

Inherited from:
Iterator
def dropWhile(p: Event => Boolean): Iterator[A]

Attributes

Inherited from:
Iterator
def duplicate: (Iterator[A], Iterator[A])

Attributes

Inherited from:
Iterator
def exists(p: Event => Boolean): Boolean

Attributes

Inherited from:
IterableOnceOps
def filter(p: Event => Boolean): Iterator[A]

Attributes

Inherited from:
Iterator
def filterNot(p: Event => Boolean): Iterator[A]

Attributes

Inherited from:
Iterator
def find(p: Event => Boolean): Option[A]

Attributes

Inherited from:
IterableOnceOps
def flatMap[B](f: Event => IterableOnce[B]): Iterator[B]

Attributes

Inherited from:
Iterator
def flatten[B](implicit ev: Event => IterableOnce[B]): Iterator[B]

Attributes

Inherited from:
Iterator
def fold[A1 >: Event](z: A1)(op: (A1, A1) => A1): A1

Attributes

Inherited from:
IterableOnceOps
def foldLeft[B](z: B)(op: (B, Event) => B): B

Attributes

Inherited from:
IterableOnceOps
def foldRight[B](z: B)(op: (Event, B) => B): B

Attributes

Inherited from:
IterableOnceOps
def forall(p: Event => Boolean): Boolean

Attributes

Inherited from:
IterableOnceOps
def foreach[U](f: Event => U): Unit

Attributes

Inherited from:
IterableOnceOps
def grouped[B >: Event](size: Int): GroupedIterator[B]

Attributes

Inherited from:
Iterator
def indexOf[B >: Event](elem: B, from: Int): Int

Attributes

Inherited from:
Iterator
def indexOf[B >: Event](elem: B): Int

Attributes

Inherited from:
Iterator
def indexWhere(p: Event => Boolean, from: Int): Int

Attributes

Inherited from:
Iterator
override def isEmpty: Boolean

Attributes

Definition Classes
Iterator -> IterableOnceOps
Inherited from:
Iterator
def isTraversableAgain: Boolean

Attributes

Inherited from:
IterableOnceOps
final def iterator: Iterator[A]

Attributes

Inherited from:
Iterator
def knownSize: Int

Attributes

Inherited from:
IterableOnce
final def length: Int

Attributes

Inherited from:
Iterator
def map[B](f: Event => B): Iterator[B]

Attributes

Inherited from:
Iterator
def max[B >: Event](implicit ord: Ordering[B]): A

Attributes

Inherited from:
IterableOnceOps
def maxBy[B](f: Event => B)(implicit cmp: Ordering[B]): A

Attributes

Inherited from:
IterableOnceOps
def maxByOption[B](f: Event => B)(implicit cmp: Ordering[B]): Option[A]

Attributes

Inherited from:
IterableOnceOps
def maxOption[B >: Event](implicit ord: Ordering[B]): Option[A]

Attributes

Inherited from:
IterableOnceOps
def min[B >: Event](implicit ord: Ordering[B]): A

Attributes

Inherited from:
IterableOnceOps
def minBy[B](f: Event => B)(implicit cmp: Ordering[B]): A

Attributes

Inherited from:
IterableOnceOps
def minByOption[B](f: Event => B)(implicit cmp: Ordering[B]): Option[A]

Attributes

Inherited from:
IterableOnceOps
def minOption[B >: Event](implicit ord: Ordering[B]): Option[A]

Attributes

Inherited from:
IterableOnceOps
final def mkString: String

Attributes

Inherited from:
IterableOnceOps
final def mkString(sep: String): String

Attributes

Inherited from:
IterableOnceOps
final def mkString(start: String, sep: String, end: String): String

Attributes

Inherited from:
IterableOnceOps
def nextOption(): Option[A]

Attributes

Inherited from:
Iterator
def nonEmpty: Boolean

Attributes

Inherited from:
IterableOnceOps
def padTo[B >: Event](len: Int, elem: B): Iterator[B]

Attributes

Inherited from:
Iterator
def partition(p: Event => Boolean): (Iterator[A], Iterator[A])

Attributes

Inherited from:
Iterator
def patch[B >: Event](from: Int, patchElems: Iterator[B], replaced: Int): Iterator[B]

Attributes

Inherited from:
Iterator
def product[B >: Event](implicit num: Numeric[B]): B

Attributes

Inherited from:
IterableOnceOps
def reduce[B >: Event](op: (B, B) => B): B

Attributes

Inherited from:
IterableOnceOps
def reduceLeft[B >: Event](op: (B, Event) => B): B

Attributes

Inherited from:
IterableOnceOps
def reduceLeftOption[B >: Event](op: (B, Event) => B): Option[B]

Attributes

Inherited from:
IterableOnceOps
def reduceOption[B >: Event](op: (B, B) => B): Option[B]

Attributes

Inherited from:
IterableOnceOps
def reduceRight[B >: Event](op: (Event, B) => B): B

Attributes

Inherited from:
IterableOnceOps
def reduceRightOption[B >: Event](op: (Event, B) => B): Option[B]

Attributes

Inherited from:
IterableOnceOps
protected def reversed: Iterable[A]

Attributes

Inherited from:
IterableOnceOps
def sameElements[B >: Event](that: IterableOnce[B]): Boolean

Attributes

Inherited from:
Iterator
def scanLeft[B](z: B)(op: (B, Event) => B): Iterator[B]

Attributes

Inherited from:
Iterator
def size: Int

Attributes

Inherited from:
IterableOnceOps
def slice(from: Int, until: Int): Iterator[A]

Attributes

Inherited from:
Iterator
def sliding[B >: Event](size: Int, step: Int): GroupedIterator[B]

Attributes

Inherited from:
Iterator
def span(p: Event => Boolean): (Iterator[A], Iterator[A])

Attributes

Inherited from:
Iterator
def splitAt(n: Int): (C, C)

Attributes

Inherited from:
IterableOnceOps
def stepper[S <: Stepper[_]](implicit shape: StepperShape[Event, S]): S

Attributes

Inherited from:
IterableOnce
def sum[B >: Event](implicit num: Numeric[B]): B

Attributes

Inherited from:
IterableOnceOps
def take(n: Int): Iterator[A]

Attributes

Inherited from:
Iterator
def takeWhile(p: Event => Boolean): Iterator[A]

Attributes

Inherited from:
Iterator
override def tapEach[U](f: Event => U): Iterator[A]

Attributes

Definition Classes
Iterator -> IterableOnceOps
Inherited from:
Iterator
def to[C1](factory: Factory[Event, C1]): C1

Attributes

Inherited from:
IterableOnceOps
def toArray[B >: Event : ClassTag]: Array[B]

Attributes

Inherited from:
IterableOnceOps
final def toBuffer[B >: Event]: Buffer[B]

Attributes

Inherited from:
IterableOnceOps
def toIndexedSeq: IndexedSeq[A]

Attributes

Inherited from:
IterableOnceOps
def toList: List[A]

Attributes

Inherited from:
IterableOnceOps
def toMap[K, V](implicit ev: Event <:< (K, V)): Map[K, V]

Attributes

Inherited from:
IterableOnceOps
def toSeq: Seq[A]

Attributes

Inherited from:
IterableOnceOps
def toSet[B >: Event]: Set[B]

Attributes

Inherited from:
IterableOnceOps
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
Iterator -> Any
Inherited from:
Iterator
def toVector: Vector[A]

Attributes

Inherited from:
IterableOnceOps
def withFilter(p: Event => Boolean): Iterator[A]

Attributes

Inherited from:
Iterator
def zip[B](that: IterableOnce[B]): Iterator[(A, B)]

Attributes

Inherited from:
Iterator
def zipAll[A1 >: Event, B](that: IterableOnce[B], thisElem: A1, thatElem: B): Iterator[(A1, B)]

Attributes

Inherited from:
Iterator
def zipWithIndex: Iterator[(A, Int)]

Attributes

Inherited from:
Iterator

Deprecated and Inherited methods

final def /:[B](z: B)(op: (B, Event) => B): B

Attributes

Deprecated
[Since version 2.13.0] Use foldLeft instead of /:
Inherited from:
IterableOnceOps
final def :\[B](z: B)(op: (Event, B) => B): B

Attributes

Deprecated
[Since version 2.13.0] Use foldRight instead of :\\
Inherited from:
IterableOnceOps
def aggregate[B](z: => B)(seqop: (B, Event) => B, combop: (B, B) => B): B

Attributes

Deprecated
[Since version 2.13.0] `aggregate` is not relevant for sequential collections. Use `foldLeft(z)(seqop)` instead.
Inherited from:
IterableOnceOps
final def copyToBuffer[B >: Event](dest: Buffer[B]): Unit

Attributes

Deprecated
[Since version 2.13.0] Use `dest ++= coll` instead
Inherited from:
IterableOnceOps
final override def hasDefiniteSize: Boolean

Attributes

Deprecated
[Since version 2.13.0] hasDefiniteSize on Iterator is the same as isEmpty
Definition Classes
Iterator -> IterableOnceOps
Inherited from:
Iterator
def scanRight[B](z: B)(op: (Event, B) => B): Iterator[B]

Attributes

Deprecated
[Since version 2.13.0] Call scanRight on an Iterable instead.
Inherited from:
Iterator
def seq: Iterator.this.type

Attributes

Deprecated
[Since version 2.13.0] Iterator.seq always returns the iterator itself
Inherited from:
Iterator
final def toIterator: Iterator[A]

Attributes

Deprecated
[Since version 2.13.0] Use .iterator instead of .toIterator
Inherited from:
IterableOnceOps
final def toStream: Stream[A]

Attributes

Deprecated
[Since version 2.13.0] Use .to(LazyList) instead of .toStream
Inherited from:
IterableOnceOps