Package: groovy.json

## [Java] Enum JsonParserType

- groovy.json.JsonParserType

-     public enum JsonParserType
      extends Enum

  Allows selection of parser type for new JsonSlurper.

  To enable the INDEX_OVERLAY parser do this: `

                   parser = new JsonSlurper().setType(JsonParserType.INDEX_OVERLAY);

  ` INDEX_OVERLAY should be your parser of choice.

  CHAR_BUFFER is the parser of choice due to element of least surprise and need to mimic existing Slurper behavior as much as possible.

  Use CHARACTER_SOURCE for large file parsing.

  Use LAX if you want to enable relaxed JSON parsing, i.e., allow comments, no quote strings, etc.

  Use CHAR_BUFFER for a non-fancy but super fast parser.

  Parser speed in order: INDEX_OVERLAY, LAX, CHAR_BUFFER, CHARACTER_SOURCE.

  Use Cases:

  Use LAX for config files as it allows comments. Use INDEX_OVERLAY for REST calls, WebSocket messages, AJAX, inter process communication, etc. Use CHAR_BUFFER if eager parsing of ints, dates, longs, are appealing. Use CHARACTER_SOURCE if you are dealing with large JSON files over 2MB. INDEX_OVERLAY is highly tuned for object deserialization from JSON.

  Since:
    2.3.0

- - ### Enum Constants Summary

    Enum constants classes
    Enum constant | Description
    --- | ---
    `CHARACTER_SOURCE` | Parser uses an abstraction that allows it to handle any size file by using a char [] windowing, built on top or Reader.
    `CHAR_BUFFER` | This is a basic parser with no index overlay.
    `INDEX_OVERLAY` | Fastest parser, but has pointers (indexes really) to original char buffer.
    `LAX` | LAX mode allows keys with no quotes, keys with single quotes, strings elements in JSON with no quotes or single quotes.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Enum` | `compareTo, compareTo, describeConstable, equals, getClass, getDeclaringClass, hashCode, name, notify, notifyAll, ordinal, toString, valueOf, wait, wait, wait`

- - ### Enum Constant Detail

    - #### JsonParserType CHARACTER_SOURCE

      Parser uses an abstraction that allows it to handle any size file by using a char [] windowing, built on top or Reader. This parser is slower than INDEX_OVERLAY and CHAR_BUFFER, but can handle really large files without OOM exceptions. Although slower than other groovy parsers it is as fast as many common JSON parsers. Recommendation is to use this for JSON buffers over 2MB.

    - #### JsonParserType CHAR_BUFFER

      This is a basic parser with no index overlay. It is wicked fast, but not as fast at the INDEX_OVERLAY. It should be on average the fastest known JSON parser on the JVM circa Jan 2014. But not as fast as INDEX_OVERLAY.

    - #### JsonParserType INDEX_OVERLAY

      Fastest parser, but has pointers (indexes really) to original char buffer. Care must be used if putting parse maps into a long term cache as members of map maybe index overlay objects pointing to original buffer. You can mitigate these risks by using chop and lazy chop. Chop eagerly dices up the buffer so each Value element points to a small copy of the original buffer. Lazy Chop dices up the buffer when a list get or map get is called so if an GPath expression or such is applied. You do not need chop or lazy chop if you are not putting the map into a long term cache. You do not need chop or lazy chop if you are doing object de-serialization. Recommendation is to use this for JSON buffers under 2MB.

    - #### JsonParserType LAX

      LAX mode allows keys with no quotes, keys with single quotes, strings elements in JSON with no quotes or single quotes. It also allows comments //, # and even multi-line /* comments. LAX is an INDEX_OVERLAY parser. Its speed is comparable to INDEX_OVERLAY. It is slightly slower than INDEX_OVERLAY, but faster than the other options.