abstract class Parser[J] extends AnyRef
Parser implements a state machine for correctly parsing JSON data.
The trait relies on a small number of methods which are left abstract, and which generalize parsing based on whether the input is in Bytes or Chars, coming from Strings, files, or other input. All methods provided here are protected, so different parsers can choose which functionality to expose.
Parser is parameterized on J, which is the type of the JSON AST it will return. Jawn can produce any AST for which a Facade[J] is available.
The parser trait does not hold any state itself, but particular implementations will usually hold state. Parser instances should not be reused between parsing runs.
For now the parser requires input to be in UTF-8. This requirement may eventually be relaxed.
- Alphabetic
 - By Inheritance
 
- Parser
 - AnyRef
 - Any
 
- Hide All
 - Show All
 
- Public
 - All
 
Instance Constructors
-  new Parser()
 
Abstract Value Members
- 
      
      
      
        
      
    
      
        abstract 
        def
      
      
        atEof(i: Int): Boolean
      
      
      
Return true iff 'i' is at or beyond the end of the input (EOF).
Return true iff 'i' is at or beyond the end of the input (EOF).
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        abstract 
        def
      
      
        char(i: Int): Char
      
      
      
Read the byte/char at 'i' as a Char.
Read the byte/char at 'i' as a Char.
Note that this should not be used on potential multi-byte sequences.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        abstract 
        def
      
      
        close(): Unit
      
      
      
Should be called when parsing is finished.
Should be called when parsing is finished.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        abstract 
        def
      
      
        column(i: Int): Int
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        abstract 
        def
      
      
        dropBufferUntil(i: Int): Unit
      
      
      
The reset() method is used to signal that we're working from the given position, and any previous data can be released.
The reset() method is used to signal that we're working from the given position, and any previous data can be released. Some parsers (e.g. StringParser) will ignore release, while others (e.g. PathParser) will need to use this information to release and allocate different areas.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        abstract 
        def
      
      
        line(): Int
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        abstract 
        def
      
      
        newline(i: Int): Unit
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        abstract 
        def
      
      
        parseString(i: Int, key: Boolean): (CharSequence, Int)
      
      
      
Parse the JSON string starting at 'i' and save it into 'ctxt'.
Parse the JSON string starting at 'i' and save it into 'ctxt'.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        abstract 
        def
      
      
        sliceString(i: Int, j: Int): CharSequence
      
      
      
Read the bytes/chars from 'i' until 'j' as a String.
Read the bytes/chars from 'i' until 'j' as a String.
- Attributes
 - protected[this]
 
 
Concrete Value Members
- 
      
      
      
        
      
    
      
        final 
        def
      
      
        !=(arg0: Any): Boolean
      
      
      
- Definition Classes
 - AnyRef → Any
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        ##(): Int
      
      
      
- Definition Classes
 - AnyRef → Any
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        ==(arg0: Any): Boolean
      
      
      
- Definition Classes
 - AnyRef → Any
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        ARRBEG: Int(6)
      
      
      
Valid parser states.
Valid parser states.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        ARREND: Int(4)
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        DATA: Int(1)
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        HexChars: Array[Int]
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        KEY: Int(2)
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        KEYVALUE: Int(2)
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        OBJBEG: Int(7)
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        OBJEND: Int(5)
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        SEP: Int(3)
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        asInstanceOf[T0]: T0
      
      
      
- Definition Classes
 - Any
 
 - 
      
      
      
        
      
    
      
        
        def
      
      
        clone(): AnyRef
      
      
      
- Attributes
 - protected[java.lang]
 - Definition Classes
 - AnyRef
 - Annotations
 - @native() @HotSpotIntrinsicCandidate() @throws( ... )
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        descape(s: CharSequence): Char
      
      
      
Generate a Char from the hex digits of "ሴ" (i.e.
Generate a Char from the hex digits of "ሴ" (i.e. "1234").
NOTE: This is only capable of generating characters from the basic plane. This is why it can only return Char instead of Int.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        
        def
      
      
        die(i: Int, msg: String): Nothing
      
      
      
Used to generate error messages with character info and offsets.
Used to generate error messages with character info and offsets.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        eq(arg0: AnyRef): Boolean
      
      
      
- Definition Classes
 - AnyRef
 
 - 
      
      
      
        
      
    
      
        
        def
      
      
        equals(arg0: Any): Boolean
      
      
      
- Definition Classes
 - AnyRef → Any
 
 - 
      
      
      
        
      
    
      
        
        def
      
      
        error(msg: String): Nothing
      
      
      
Used to generate messages for internal errors.
Used to generate messages for internal errors.
This should only be used in situations where a possible bug in the parser was detected. For errors in user-provided JSON, use die().
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        getClass(): Class[_]
      
      
      
- Definition Classes
 - AnyRef → Any
 - Annotations
 - @native() @HotSpotIntrinsicCandidate()
 
 - 
      
      
      
        
      
    
      
        
        def
      
      
        hashCode(): Int
      
      
      
- Definition Classes
 - AnyRef → Any
 - Annotations
 - @native() @HotSpotIntrinsicCandidate()
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        isInstanceOf[T0]: Boolean
      
      
      
- Definition Classes
 - Any
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        ne(arg0: AnyRef): Boolean
      
      
      
- Definition Classes
 - AnyRef
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        notify(): Unit
      
      
      
- Definition Classes
 - AnyRef
 - Annotations
 - @native() @HotSpotIntrinsicCandidate()
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        notifyAll(): Unit
      
      
      
- Definition Classes
 - AnyRef
 - Annotations
 - @native() @HotSpotIntrinsicCandidate()
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        parse(i: Int, facade: Visitor[_, J]): (J, Int)
      
      
      
Parse and return the next JSON value and the position beyond it.
Parse and return the next JSON value and the position beyond it.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        parse(facade: Visitor[_, J]): J
      
      
      
Parse the JSON document into a single JSON value.
Parse the JSON document into a single JSON value.
The parser considers documents like '333', 'true', and '"foo"' to be valid, as well as more traditional documents like [1,2,3,4,5]. However, multiple top-level objects are not allowed.
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        parseFalse(i: Int, facade: Visitor[_, J]): J
      
      
      
Parse the JSON constant "false".
Parse the JSON constant "false".
Note that this method assumes that the first character has already been checked.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        parseNull(i: Int, facade: Visitor[_, J]): J
      
      
      
Parse the JSON constant "null".
Parse the JSON constant "null".
Note that this method assumes that the first character has already been checked.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        parseNum(i: Int, ctxt: ObjArrVisitor[Any, J], facade: Visitor[_, J]): Int
      
      
      
Parse the given number, and add it to the given context.
Parse the given number, and add it to the given context.
We don't actually instantiate a number here, but rather pass the string of for future use. Facades can choose to be lazy and just store the string. This ends up being way faster and has the nice side-effect that we know exactly how the user represented the number.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        parseNumSlow(i: Int, facade: Visitor[_, J]): (J, Int)
      
      
      
Parse the given number, and add it to the given context.
Parse the given number, and add it to the given context.
This method is a bit slower than parseNum() because it has to be sure it doesn't run off the end of the input.
Normally (when operating in rparse in the context of an outer array or object) we don't need to worry about this and can just grab characters, because if we run out of characters that would indicate bad input. This is for cases where the number could possibly be followed by a valid EOF.
This method has all the same caveats as the previous method.
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        parseTrue(i: Int, facade: Visitor[_, J]): J
      
      
      
Parse the JSON constant "true".
Parse the JSON constant "true".
Note that this method assumes that the first character has already been checked.
- Attributes
 - protected[this]
 
 -  def reject(j: Int): PartialFunction[Throwable, Nothing]
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        rparse(state: Int, j: Int, stack: List[ObjArrVisitor[_, J]]): (J, Int)
      
      
      
Tail-recursive parsing method to do the bulk of JSON parsing.
Tail-recursive parsing method to do the bulk of JSON parsing.
This single method manages parser states, data, etc. Except for parsing non-recursive values (like strings, numbers, and constants) all important work happens in this loop (or in methods it calls, like reset()).
Currently the code is optimized to make use of switch statements. Future work should consider whether this is better or worse than manually constructed if/else statements or something else. Also, it may be possible to reorder some cases for speed improvements.
- j
 index/position in the source json
- Attributes
 - protected[this]
 - Annotations
 - @tailrec()
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        synchronized[T0](arg0: ⇒ T0): T0
      
      
      
- Definition Classes
 - AnyRef
 
 - 
      
      
      
        
      
    
      
        
        def
      
      
        toString(): String
      
      
      
- Definition Classes
 - AnyRef → Any
 
 - 
      
      
      
        
      
    
      
        final 
        val
      
      
        utf8: Charset
      
      
      
- Attributes
 - protected[this]
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        wait(arg0: Long, arg1: Int): Unit
      
      
      
- Definition Classes
 - AnyRef
 - Annotations
 - @throws( ... )
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        wait(arg0: Long): Unit
      
      
      
- Definition Classes
 - AnyRef
 - Annotations
 - @native() @throws( ... )
 
 - 
      
      
      
        
      
    
      
        final 
        def
      
      
        wait(): Unit
      
      
      
- Definition Classes
 - AnyRef
 - Annotations
 - @throws( ... )