JsonParser

trait JsonParser extends Iterator[Event] with AutoCloseable

Defines JSON parser.

import little.json.*
import little.json.Implicits.given
import scala.language.implicitConversions

import JsonParser.Event

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

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

 // Get field name and value
 assert { parser.next() == Event.FieldName("id") }
 assert { parser.next() == Event.Value(1000) }

 // Get field name and value
 assert { parser.next() == Event.FieldName("name") }
 assert { parser.next() == Event.Value("jza") }

 // Get field name and value
 assert { parser.next() == Event.FieldName("groups") }
 assert { parser.next() == Event.StartArray } // start nested array
 assert { parser.next() == Event.Value("jza") }
 assert { parser.next() == Event.Value("adm") }
 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()
See also
Companion
object
trait AutoCloseable
trait Iterator[Event]
trait IterableOnceOps[Event, [A] =>> Iterator[A], Iterator[Event]]
trait IterableOnce[Event]
class Object
trait Matchable
class Any

Type members

Inherited classlikes

class GroupedIterator[B >: A]
Inherited from
Iterator

Value members

Abstract methods

def close(): Unit

Closes parser.

Closes parser.

Parses and collects remainder of current JSON array.

Parses and collects remainder of current JSON array.

import little.json.Implicits.{ *, given }
import little.json.{ Json, JsonParser }
import scala.language.implicitConversions

import JsonParser.Event

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

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

Parser must be in array context.

Parses and collects remainder of current JSON object.

Parses and collects remainder of current JSON object.

import little.json.Implicits.{ *, given }
import little.json.{ Json, JsonParser }
import scala.language.implicitConversions

import JsonParser.Event

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

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

Parser must be in object context, and previous event must not be field name.

def hasNext: Boolean

Tests for next event.

Tests for next event.

def next(): Event

Gets next event.

Gets next event.

Inherited methods

@inline
final def ++[B >: Event](xs: => IterableOnce[B]): Iterator[B]
Inherited from
Iterator
@inline
final def addString(b: StringBuilder): StringBuilder
Inherited from
IterableOnceOps
@inline
final def addString(b: StringBuilder, sep: String): StringBuilder
Inherited from
IterableOnceOps
def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder
Inherited from
IterableOnceOps
def buffered: BufferedIterator[Event]
Inherited from
Iterator
def collect[B](pf: PartialFunction[Event, B]): Iterator[B]
Inherited from
Iterator
def collectFirst[B](pf: PartialFunction[Event, B]): Option[B]
Inherited from
IterableOnceOps
def concat[B >: Event](xs: => IterableOnce[B]): Iterator[B]
Inherited from
Iterator
def contains(elem: Any): Boolean
Inherited from
Iterator
def copyToArray[B >: Event](xs: Array[B], start: Int, len: Int): Int
Inherited from
IterableOnceOps
@deprecatedOverriding(message = "This should always forward to the 3-arg version of this method", since = "2.13.4")
def copyToArray[B >: Event](xs: Array[B], start: Int): Int
Inherited from
IterableOnceOps
@deprecatedOverriding(message = "This should always forward to the 3-arg version of this method", since = "2.13.4")
def copyToArray[B >: Event](xs: Array[B]): Int
Inherited from
IterableOnceOps
def corresponds[B](that: IterableOnce[B])(p: (Event, B) => Boolean): Boolean
Inherited from
IterableOnceOps
def count(p: Event => Boolean): Int
Inherited from
IterableOnceOps
def distinct: Iterator[Event]
Inherited from
Iterator
def distinctBy[B](f: Event => B): Iterator[Event]
Inherited from
Iterator
def drop(n: Int): Iterator[Event]
Inherited from
Iterator
def dropWhile(p: Event => Boolean): Iterator[Event]
Inherited from
Iterator
def duplicate: (Iterator[Event], Iterator[Event])
Inherited from
Iterator
def exists(p: Event => Boolean): Boolean
Inherited from
IterableOnceOps
def filter(p: Event => Boolean): Iterator[Event]
Inherited from
Iterator
def filterNot(p: Event => Boolean): Iterator[Event]
Inherited from
Iterator
def find(p: Event => Boolean): Option[Event]
Inherited from
IterableOnceOps
def flatMap[B](f: Event => IterableOnce[B]): Iterator[B]
Inherited from
Iterator
def flatten[B](implicit ev: Event => IterableOnce[B]): Iterator[B]
Inherited from
Iterator
def fold[A1 >: Event](z: A1)(op: (A1, A1) => A1): A1
Inherited from
IterableOnceOps
def foldLeft[B](z: B)(op: (B, Event) => B): B
Inherited from
IterableOnceOps
def foldRight[B](z: B)(op: (Event, B) => B): B
Inherited from
IterableOnceOps
def forall(p: Event => Boolean): Boolean
Inherited from
IterableOnceOps
def foreach[U](f: Event => U): Unit
Inherited from
IterableOnceOps
def grouped[B >: Event](size: Int): GroupedIterator[B]
Inherited from
Iterator
def indexOf[B >: Event](elem: B, from: Int): Int
Inherited from
Iterator
def indexOf[B >: Event](elem: B): Int
Inherited from
Iterator
def indexWhere(p: Event => Boolean, from: Int): Int
Inherited from
Iterator
@deprecatedOverriding(message = "isEmpty is defined as !hasNext; override hasNext instead", since = "2.13.0")
override def isEmpty: Boolean
Definition Classes
Iterator -> IterableOnceOps
Inherited from
Iterator
def isTraversableAgain: Boolean
Inherited from
IterableOnceOps
@inline
final def iterator: Iterator[Event]
Inherited from
Iterator
def knownSize: Int
Inherited from
IterableOnce
@inline
final def length: Int
Inherited from
Iterator
def map[B](f: Event => B): Iterator[B]
Inherited from
Iterator
def max[B >: Event](implicit ord: Ordering[B]): Event
Inherited from
IterableOnceOps
def maxBy[B](f: Event => B)(implicit cmp: Ordering[B]): Event
Inherited from
IterableOnceOps
def maxByOption[B](f: Event => B)(implicit cmp: Ordering[B]): Option[Event]
Inherited from
IterableOnceOps
def maxOption[B >: Event](implicit ord: Ordering[B]): Option[Event]
Inherited from
IterableOnceOps
def min[B >: Event](implicit ord: Ordering[B]): Event
Inherited from
IterableOnceOps
def minBy[B](f: Event => B)(implicit cmp: Ordering[B]): Event
Inherited from
IterableOnceOps
def minByOption[B](f: Event => B)(implicit cmp: Ordering[B]): Option[Event]
Inherited from
IterableOnceOps
def minOption[B >: Event](implicit ord: Ordering[B]): Option[Event]
Inherited from
IterableOnceOps
@inline
final def mkString: String
Inherited from
IterableOnceOps
@inline
final def mkString(sep: String): String
Inherited from
IterableOnceOps
final def mkString(start: String, sep: String, end: String): String
Inherited from
IterableOnceOps
def nextOption(): Option[Event]
Inherited from
Iterator
@deprecatedOverriding(message = "nonEmpty is defined as !isEmpty; override isEmpty instead", since = "2.13.0")
def nonEmpty: Boolean
Inherited from
IterableOnceOps
def padTo[B >: Event](len: Int, elem: B): Iterator[B]
Inherited from
Iterator
def partition(p: Event => Boolean): (Iterator[Event], Iterator[Event])
Inherited from
Iterator
def patch[B >: Event](from: Int, patchElems: Iterator[B], replaced: Int): Iterator[B]
Inherited from
Iterator
def product[B >: Event](implicit num: Numeric[B]): B
Inherited from
IterableOnceOps
def reduce[B >: Event](op: (B, B) => B): B
Inherited from
IterableOnceOps
def reduceLeft[B >: Event](op: (B, Event) => B): B
Inherited from
IterableOnceOps
def reduceLeftOption[B >: Event](op: (B, Event) => B): Option[B]
Inherited from
IterableOnceOps
def reduceOption[B >: Event](op: (B, B) => B): Option[B]
Inherited from
IterableOnceOps
def reduceRight[B >: Event](op: (Event, B) => B): B
Inherited from
IterableOnceOps
def reduceRightOption[B >: Event](op: (Event, B) => B): Option[B]
Inherited from
IterableOnceOps
protected def reversed: Iterable[Event]
Inherited from
IterableOnceOps
def sameElements[B >: Event](that: IterableOnce[B]): Boolean
Inherited from
Iterator
def scanLeft[B](z: B)(op: (B, Event) => B): Iterator[B]
Inherited from
Iterator
def size: Int
Inherited from
IterableOnceOps
def slice(from: Int, until: Int): Iterator[Event]
Inherited from
Iterator
def sliding[B >: Event](size: Int, step: Int): GroupedIterator[B]
Inherited from
Iterator
def span(p: Event => Boolean): (Iterator[Event], Iterator[Event])
Inherited from
Iterator
def splitAt(n: Int): (Iterator[Event], Iterator[Event])
Inherited from
IterableOnceOps
def stepper[S <: Stepper[_]](implicit shape: StepperShape[Event, S]): S
Inherited from
IterableOnce
def sum[B >: Event](implicit num: Numeric[B]): B
Inherited from
IterableOnceOps
def take(n: Int): Iterator[Event]
Inherited from
Iterator
def takeWhile(p: Event => Boolean): Iterator[Event]
Inherited from
Iterator
override def tapEach[U](f: Event => U): Iterator[Event]
Definition Classes
Iterator -> IterableOnceOps
Inherited from
Iterator
def to[C1](factory: Factory[Event, C1]): C1
Inherited from
IterableOnceOps
def toArray[B >: Event](implicit ClassTag[B]): Array[B]
Inherited from
IterableOnceOps
@inline
final def toBuffer[B >: Event]: Buffer[B]
Inherited from
IterableOnceOps
def toIndexedSeq: IndexedSeq[Event]
Inherited from
IterableOnceOps
def toList: List[Event]
Inherited from
IterableOnceOps
def toMap[K, V](implicit ev: Event <:< (K, V)): Map[K, V]
Inherited from
IterableOnceOps
def toSeq: Seq[Event]
Inherited from
IterableOnceOps
def toSet[B >: Event]: Set[B]
Inherited from
IterableOnceOps
override def toString(): String
Definition Classes
Iterator -> Any
Inherited from
Iterator
def toVector: Vector[Event]
Inherited from
IterableOnceOps
def withFilter(p: Event => Boolean): Iterator[Event]
Inherited from
Iterator
def zip[B](that: IterableOnce[B]): Iterator[(Event, B)]
Inherited from
Iterator
def zipAll[A1 >: Event, B](that: IterableOnce[B], thisElem: A1, thatElem: B): Iterator[(A1, B)]
Inherited from
Iterator
def zipWithIndex: Iterator[(Event, Int)]
Inherited from
Iterator

Deprecated and Inherited methods

@inline @deprecated(message = "Use foldLeft instead of /:", since = "2.13.0")
final def /:[B](z: B)(op: (B, Event) => B): B
Deprecated
[Since version 2.13.0] Use foldLeft instead of /:
Inherited from
IterableOnceOps
@inline @deprecated(message = "Use foldRight instead of :\\", since = "2.13.0")
final def :\[B](z: B)(op: (Event, B) => B): B
Deprecated
[Since version 2.13.0] Use foldRight instead of :\\
Inherited from
IterableOnceOps
@deprecated(message = "`aggregate` is not relevant for sequential collections. Use `foldLeft(z)(seqop)` instead.", since = "2.13.0")
def aggregate[B](z: => B)(seqop: (B, Event) => B, combop: (B, B) => B): B
Deprecated
[Since version 2.13.0] `aggregate` is not relevant for sequential collections. Use `foldLeft(z)(seqop)` instead.
Inherited from
IterableOnceOps
@inline @deprecated(message = "Use `dest ++= coll` instead", since = "2.13.0")
final def copyToBuffer[B >: Event](dest: Buffer[B]): Unit
Deprecated
[Since version 2.13.0] Use `dest ++= coll` instead
Inherited from
IterableOnceOps
@inline @deprecated(message = "hasDefiniteSize on Iterator is the same as isEmpty", since = "2.13.0")
final override def hasDefiniteSize: Boolean
Deprecated
[Since version 2.13.0] hasDefiniteSize on Iterator is the same as isEmpty
Definition Classes
Iterator -> IterableOnceOps
Inherited from
Iterator
@deprecated(message = "Call scanRight on an Iterable instead.", since = "2.13.0")
def scanRight[B](z: B)(op: (Event, B) => B): Iterator[B]
Deprecated
[Since version 2.13.0] Call scanRight on an Iterable instead.
Inherited from
Iterator
@deprecated(message = "Iterator.seq always returns the iterator itself", since = "2.13.0")
Deprecated
[Since version 2.13.0] Iterator.seq always returns the iterator itself
Inherited from
Iterator
@inline @deprecated(message = "Use .iterator instead of .toIterator", since = "2.13.0")
final def toIterator: Iterator[Event]
Deprecated
[Since version 2.13.0] Use .iterator instead of .toIterator
Inherited from
IterableOnceOps
@inline @deprecated(message = "Use .to(LazyList) instead of .toStream", since = "2.13.0")
final def toStream: Stream[Event]
Deprecated
[Since version 2.13.0] Use .to(LazyList) instead of .toStream
Inherited from
IterableOnceOps