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
Members list
Type members
Inherited classlikes
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 Objecttrait Matchableclass AnyShow all
Value members
Abstract methods
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.
Tests for next event.
Tests for next event.
Attributes
Inherited methods
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Attributes
- Definition Classes
-
Iterator -> IterableOnceOps
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnce
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnce
Attributes
- Inherited from:
- Iterator
Attributes
- Definition Classes
-
Iterator -> IterableOnceOps
- Inherited from:
- Iterator
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
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
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Attributes
- Inherited from:
- Iterator
Deprecated and Inherited methods
Attributes
- Deprecated
-
[Since version 2.13.0]
Use foldLeft instead of /: - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
Use foldRight instead of :\\ - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
`aggregate` is not relevant for sequential collections. Use `foldLeft(z)(seqop)` instead. - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
Use `dest ++= coll` instead - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
hasDefiniteSize on Iterator is the same as isEmpty - Definition Classes
-
Iterator -> IterableOnceOps
- Inherited from:
- Iterator
Attributes
- Deprecated
-
[Since version 2.13.0]
Call scanRight on an Iterable instead. - Inherited from:
- Iterator
Attributes
- Deprecated
-
[Since version 2.13.0]
Iterator.seq always returns the iterator itself - Inherited from:
- Iterator
Attributes
- Deprecated
-
[Since version 2.13.0]
Use .iterator instead of .toIterator - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
Use .to(LazyList) instead of .toStream - Inherited from:
- IterableOnceOps
In this article