KEMBAR78
JParse Fast JSON Parser | PDF
JParse
Another JSON Parser
https://github.com/RichardHightower/jparse
• Wrote Boon
• Java utility lib, that became a JSON Parser through a $100 bet
• Wrote QBit, Crank, worked a lot with Vert.x and Akka
About Me
Boon got some attention
• InfoQ article
• Adopted as part of Groovy
• GSON hash attack benchmark
• Benchmarks and response to bench marks
Boon’s day in the sun
4/30/2014
Why a new Parser?
• Why not just update Boon?
• Large, was meant to be a utility lib and became a JSON parser
• 90,000 LoC in (just Java not including test classes)
• Does too many things that no one uses
• Uses index overlay but was not originally designed to use Index Overlay
• Uses Unsafe which is not allowed in new JVMs
JParse
• Just a JSON parser plus a small subset of JSONPath
• Small (currently 4200 lines of code)
• Status:
• Perf tuned and worked on usable,
fl
uent API
• Does not use Unsafe
• Very fast, uses an index overlay from the ground up
• Does not do JavaBean serialization but can serialize into basic Java types
Is JParse fast?
Benchmark Mode Cnt Score Error Units
BenchMark.simpleDeserializeJJsonWebXML thrpt 2 237334.575 ops/s
BenchMark.simpleDeserializeJacksonWebXML thrpt 2 114135.958 ops/s
YES!
Caveat on Benchmarks
• JParse is being actively developed, as we add features or make
improvements, it can impact benchmarks
• JParse is focused only on Parse and mini JSONPath
• JParse does not have very many features
• JParse only supports JSON as de
fi
ned by json.org
• No extensions
• No advanced mappings
Benchmark Mode Cnt Score Error Units
BenchMark.deserializeIntoMapJParseAndGetPathThenSerialize thrpt 2 788400.189 ops/s
BenchMark.deserializeIntoMapJacksonAndGetPathThenSerialize thrpt 2 285313.787 ops/s
Path lookup
Conclusion for Benchmarks
• Parsers got a lot faster
• Jackson got a lot faster in 9 years
• Other parsers are fast too
• Not as easy to win as it was 9 years ago
Example usage
Slicing and dicing JSON
Supports JSONPath subset
Easy to access properties
No special API, just Java types
Basic Java types
• java.lang.Number (JSON number)
• java.util.List (JSON array)
• Java array (e.g., int[]) (JSON array)
• java.lang.CharSequence (JSON String)
• java.util.Map (JSON object)
Easy to combine Java functional programming
JSON Array is just a Java list so you can do stream/functional programming
Helper functions to make Java functional
programming easier with JParse
Versus this!
Easy to use functional support
For custom mapping
Easy to use functional support
For custom mapping part 2
Easy to pull off properties
You can also work with nodes directly for more
conversions and such
Many characters sources
InputStream, CharBu
ff
er, char[], String, Reader, File,
CharSequence (StringBuilder) etc.
Nodes are all basic Java types
• ArrayNode is a java.util.List
• ObjectNode is a Map
• All nodes are CharSequences
• NumberNode is java.lang.Number (toInt, toFloat, toDouble, toShort, etc.)
• StringNode is a CharSequence and works well with Strings (toUnencodedString, toString, toEncodedString)
Easy to learn!
Primitive Float Arrays
INT Arrays
Continue to use Jackson
• Used in a lot of projects
• Support for other data formats
• Advanced Mappings
• But large
When to use JParse
• You want a small footprint JSON parser that is fast
• You don’t need advanced mappings and are willing and able to map using
Functional programming
JParse
• Not done yet (BenchMark will change)
• Still needs to improve error handling
• Virtually none so no real useful messages if their are errors
• Boon had really excellent error messages and JParse will to
• Does not support any extras (by design)
• Does not support NaN, +In
fi
nity, -In
fi
nity because that is not in the JSON org spec.
• Does not support any attribute keys but Strings (JSON org spec.)
• Just strict JSON no minimal JSON

JParse Fast JSON Parser

  • 1.
  • 2.
    • Wrote Boon •Java utility lib, that became a JSON Parser through a $100 bet • Wrote QBit, Crank, worked a lot with Vert.x and Akka About Me
  • 3.
    Boon got someattention • InfoQ article • Adopted as part of Groovy • GSON hash attack benchmark • Benchmarks and response to bench marks
  • 4.
    Boon’s day inthe sun 4/30/2014
  • 5.
    Why a newParser? • Why not just update Boon? • Large, was meant to be a utility lib and became a JSON parser • 90,000 LoC in (just Java not including test classes) • Does too many things that no one uses • Uses index overlay but was not originally designed to use Index Overlay • Uses Unsafe which is not allowed in new JVMs
  • 6.
    JParse • Just aJSON parser plus a small subset of JSONPath • Small (currently 4200 lines of code) • Status: • Perf tuned and worked on usable, fl uent API • Does not use Unsafe • Very fast, uses an index overlay from the ground up • Does not do JavaBean serialization but can serialize into basic Java types
  • 7.
    Is JParse fast? BenchmarkMode Cnt Score Error Units BenchMark.simpleDeserializeJJsonWebXML thrpt 2 237334.575 ops/s BenchMark.simpleDeserializeJacksonWebXML thrpt 2 114135.958 ops/s YES!
  • 8.
    Caveat on Benchmarks •JParse is being actively developed, as we add features or make improvements, it can impact benchmarks • JParse is focused only on Parse and mini JSONPath • JParse does not have very many features • JParse only supports JSON as de fi ned by json.org • No extensions • No advanced mappings
  • 9.
    Benchmark Mode CntScore Error Units BenchMark.deserializeIntoMapJParseAndGetPathThenSerialize thrpt 2 788400.189 ops/s BenchMark.deserializeIntoMapJacksonAndGetPathThenSerialize thrpt 2 285313.787 ops/s
  • 10.
  • 11.
    Conclusion for Benchmarks •Parsers got a lot faster • Jackson got a lot faster in 9 years • Other parsers are fast too • Not as easy to win as it was 9 years ago
  • 12.
  • 13.
    Slicing and dicingJSON Supports JSONPath subset
  • 14.
    Easy to accessproperties
  • 15.
    No special API,just Java types
  • 16.
    Basic Java types •java.lang.Number (JSON number) • java.util.List (JSON array) • Java array (e.g., int[]) (JSON array) • java.lang.CharSequence (JSON String) • java.util.Map (JSON object)
  • 17.
    Easy to combineJava functional programming JSON Array is just a Java list so you can do stream/functional programming
  • 18.
    Helper functions tomake Java functional programming easier with JParse Versus this!
  • 19.
    Easy to usefunctional support For custom mapping
  • 20.
    Easy to usefunctional support For custom mapping part 2
  • 21.
    Easy to pulloff properties
  • 22.
    You can alsowork with nodes directly for more conversions and such
  • 23.
    Many characters sources InputStream,CharBu ff er, char[], String, Reader, File, CharSequence (StringBuilder) etc.
  • 24.
    Nodes are allbasic Java types • ArrayNode is a java.util.List • ObjectNode is a Map • All nodes are CharSequences • NumberNode is java.lang.Number (toInt, toFloat, toDouble, toShort, etc.) • StringNode is a CharSequence and works well with Strings (toUnencodedString, toString, toEncodedString) Easy to learn!
  • 25.
  • 26.
  • 27.
    Continue to useJackson • Used in a lot of projects • Support for other data formats • Advanced Mappings • But large
  • 28.
    When to useJParse • You want a small footprint JSON parser that is fast • You don’t need advanced mappings and are willing and able to map using Functional programming
  • 29.
    JParse • Not doneyet (BenchMark will change) • Still needs to improve error handling • Virtually none so no real useful messages if their are errors • Boon had really excellent error messages and JParse will to • Does not support any extras (by design) • Does not support NaN, +In fi nity, -In fi nity because that is not in the JSON org spec. • Does not support any attribute keys but Strings (JSON org spec.) • Just strict JSON no minimal JSON