DEV Community

Yu Han
Yu Han

Posted on

SJF4J vs Jayway JsonPath: Up to 7x Faster in Java Benchmarks

We benchmarked JSONPath in Java.

SJF4J: https://github.com/sjf4j-projects/sjf4j

Jayway JsonPath: https://github.com/json-path/JsonPath

Result:

SJF4J is up to 7x faster.

Here’s what we found.


Benchmark Setup

We built a JMH benchmark suite comparing:

  • SJF4J v1.5.0
  • Jayway JsonPath v2.9.0

Across three workload shapes:

  • Path compilation
  • Query on shared JsonNode
  • Query on Map/List object graphs

JMH config:

  • 5 Γ— 300ms warmup
  • 8 Γ— 300ms measurement
  • 2 forks
  • 1 thread

Expressions used:

  • $.store.book[1].price
  • $.store.bicycle.color
  • $.store.book[*].author
  • $..price
  • $.store.book[?(@.price > 10)].title
  • $.store.book[0,2].title

Headline Results

Geometric mean (lower is better):

Benchmark group SJF4J Jayway Result
compile 97 ns/op 125 ns/op SJF4J 1.28x faster
query_definite 100 ns/op 237 ns/op SJF4J 2.38x faster
query_indefinite 656 ns/op 1294 ns/op SJF4J 1.97x faster
query_map_list_definite 31 ns/op 200 ns/op SJF4J 6.38x faster
query_map_list_indefinite 280 ns/op 1301 ns/op SJF4J 4.65x faster

TL;DR

  • ~2x faster on typical queries
  • up to 7x faster on Map/List
  • faster compilation as well

1) Query on Shared JsonNode

This is the fairest comparison: both libraries query the same parsed tree.

Definite paths

Expression SJF4J Jayway Result
$.store.book[1].price 111 ns/op 260 ns/op 2.35x faster
$.store.bicycle.color 90 ns/op 216 ns/op 2.40x faster

Indefinite paths

Expression SJF4J Jayway Result
$.store.book[*].author 342 ns/op 910 ns/op 2.66x faster
$..price 1736 ns/op 3877 ns/op 2.23x faster
$.store.book[?(@.price > 10)].title 1292 ns/op 1660 ns/op 1.29x faster
$.store.book[0,2].title 242 ns/op 478 ns/op 1.98x faster

Conclusion:

SJF4J is consistently faster as a JSONPath engine.


πŸš€ 2) Query on Map/List Object Graphs

This is where the gap becomes much larger.

Both libraries support Map/List style object graphs, so this is still a fair comparison.

Definite paths

Expression SJF4J Jayway Result
$.store.book[1].price 37 ns/op 280 ns/op 7.50x faster
$.store.bicycle.color 26 ns/op 142 ns/op 5.42x faster

Indefinite paths

Expression SJF4J Jayway Result
$.store.book[*].author 135 ns/op 1045 ns/op 7.73x faster
$..price 543 ns/op 2495 ns/op 4.59x faster
$.store.book[?(@.price > 10)].title 823 ns/op 1836 ns/op 2.23x faster
$.store.book[0,2].title 102 ns/op 598 ns/op 5.89x faster

Takeaway:

If your application already works on Map/List object graphs,

this is the strongest result in the entire benchmark.


πŸ”₯ 3) Native Object Graphs: POJO / JOJO

This is where SJF4J goes beyond traditional JSONPath libraries.

Instead of forcing everything into a JSON AST, SJF4J runs directly on:

  • Map / List
  • JOJO (JSON Object + Java Object hybrid)
  • POJO

Jayway does not support this model natively.

So here we compare SJF4J across different object representations.

Geometric mean

Benchmark group Map/List JOJO POJO
definite 31 ns/op 43 ns/op 94 ns/op
indefinite 270 ns/op 373 ns/op 554 ns/op

Representative results

Expression Map/List JOJO POJO
$.store.book[1].price 37 ns/op 46 ns/op 102 ns/op
$.store.bicycle.color 26 ns/op 40 ns/op 87 ns/op
$.store.book[*].author 131 ns/op 196 ns/op 374 ns/op
$..price 496 ns/op 914 ns/op 955 ns/op
$.store.book[?(@.price > 10)].title 807 ns/op 876 ns/op 1100 ns/op

What this shows:

  • Map/List is fastest (no abstraction)
  • JOJO adds minimal overhead
  • POJO is slower, but still practical

The key insight:

You can run JSONPath directly on your domain model.

No conversion. No intermediate tree.


What This Means in Practice

Instead of:

POJO β†’ JsonNode β†’ JSONPath β†’ result

You can do:

POJO β†’ JSONPath β†’ result

This removes an entire layer from your data processing pipeline.


Why Is SJF4J Faster?

The performance difference mainly comes from:

  • no forced conversion into a dedicated AST
  • direct execution on native Java object graphs
  • lower abstraction overhead in path evaluation

In short:

SJF4J avoids work that other libraries must do first.


Bottom Line

Jayway is fine for basic JSONPath usage.

But if performance matters, especially on Map/List or POJO object graphs:

SJF4J is simply faster.


Links

GitHub: https://github.com/sjf4j-projects/sjf4j

Benchmark source: JsonPathCompareBenchmark.java

Top comments (0)