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
Type members
Inherited classlikes
Value members
Abstract methods
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.
Inherited methods
@deprecatedOverriding(message = "This should always forward to the 3-arg version of this method", since = "2.13.4")
- Inherited from
- IterableOnceOps
@deprecatedOverriding(message = "This should always forward to the 3-arg version of this method", since = "2.13.4")
- Inherited from
- IterableOnceOps
@deprecatedOverriding(message = "isEmpty is defined as !hasNext; override hasNext instead", since = "2.13.0")
- Definition Classes
- Iterator -> IterableOnceOps
- Inherited from
- Iterator
@deprecatedOverriding(message = "nonEmpty is defined as !isEmpty; override isEmpty instead", since = "2.13.0")
- Inherited from
- IterableOnceOps
Deprecated and Inherited methods
@inline @deprecated(message = "Use foldLeft instead of /:", since = "2.13.0")
- Deprecated
[Since version 2.13.0]
Use foldLeft instead of /:- Inherited from
- IterableOnceOps
@inline @deprecated(message = "Use foldRight instead of :\\", since = "2.13.0")
- 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")
- 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")
- 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")
- 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")
- 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