Skip to content

Latest commit

 

History

222 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONPath Benchmark

Benchmark JSONPath

This project benchmarks multiple JSONPath libraries written in Go. It evaluates performance in specific scenarios and offers guidance for selecting an appropriate library.

Contents

Overview

Results are generated via GitHub Actions for consistency and automation.

The benchmark focuses on the per-operation cost after initial setup is complete. Preparatory steps, such as parsing or preloading data, are excluded from the measurements. Instead, it emphasizes scenarios with intensive looping or query execution within the main operation.

Results may vary with factors such as input structure, query complexity, and runtime environment. Treat these benchmarks as a general reference and re-evaluate them periodically.

Notes on metrics:

  • Time: ns/op (lower is better)
  • Memory: B/op (lower is better)
  • Allocations: allocs/op (lower is better)

Libraries Benchmarked

The following libraries are included in this benchmark:

Simple Query Performance

JSONPath:

$.store.book[*].price

Summary:

  • Query features:
    • root selector ($)
    • child segments (name selectors)
    • wildcard selector ([*])
  • Compatibility: 10/10 (all libraries)
  • Fastest: AsaiYusuke/JSONPath

Performance Detail:

Rank Library Time (ns/op) Memory (B/op) Allocations (allocs/op) Relative speed (fastest = 1x)
1 AsaiYusuke/JSONPath (reuse) 118.50 0 0 1.00x
2 AsaiYusuke/JSONPath 170.70 64 1 1.44x
3 Yalp/JSONPath 292.40 160 5 2.47x
4 oliveagle/JsonPath 375.40 160 5 3.17x
5 ohler55/OjG (jp) 560.50 1264 4 4.73x
6 theory/RFC 9535 JSONPath in Go 756.80 464 20 6.39x
7 PaesslerAG/JSONPath 1385.00 816 29 11.69x
8 vmware-labs/YAML JSONPath 2179.00 1240 67 18.39x
9 Spyzhov/Abstract JSON 2474.00 968 30 20.88x
10 bhmj/JSONSlice 4181.00 312 13 35.28x

Simple query benchmark (ns/op)

Complex Query Performance

JSONPath:

$..book[?(@.price > $.store.bicycle.price)]

Summary:

  • Query features:
    • root selector ($)
    • descendant segment (..)
    • filter selector (?()) with comparison expression
    • path references (@ and $)
    • child segments (name selectors)
  • Compatibility: 6/10 (see Support Matrix)
  • Fastest: AsaiYusuke/JSONPath

Performance Detail:

Rank Library Time (ns/op) Memory (B/op) Allocations (allocs/op) Relative speed (fastest = 1x)
1 AsaiYusuke/JSONPath (reuse) 1152.00 80 2 1.00x
2 AsaiYusuke/JSONPath 1188.00 96 3 1.03x
3 theory/RFC 9535 JSONPath in Go 3415.00 1408 66 2.96x
4 ohler55/OjG (jp) 4092.00 6200 37 3.55x
5 bhmj/JSONSlice 15926.00 1728 35 13.82x
6 Spyzhov/Abstract JSON 16226.00 5464 222 14.09x

Complex query benchmark (ns/op)

Support Matrix

Library Simple query Complex query
AsaiYusuke/JSONPath (reuse) ✅ ✅
AsaiYusuke/JSONPath ✅ ✅
PaesslerAG/JSONPath ✅ ❌
bhmj/JSONSlice ✅ ✅
ohler55/OjG (jp) ✅ ✅
oliveagle/JsonPath ✅ ❌
Spyzhov/Abstract JSON ✅ ✅
theory/RFC 9535 JSONPath in Go ✅ ✅
vmware-labs/YAML JSONPath ✅ ❌
Yalp/JSONPath ✅ ❌

Conclusion

This benchmark compared several popular JSONPath libraries in Go and highlighted notable performance differences. Interestingly, the simple query showed a wider performance spread than the complex one, suggesting that implementation details and variations in query syntax handling can directly impact execution speed. Therefore, a practical evaluation should consider both feature support and raw performance. For selecting a library in production, we strongly recommend running benchmarks tailored to your own datasets and query patterns.

Reproduce Locally

Benchmarks are executed in GitHub Actions for consistency. For the exact steps and current outputs, check the Actions tab and the workflow logs. If you prefer to run locally, follow the same sequence defined in the workflow file (see .github/workflows/build.yml).

License

This project is distributed under the terms of the MIT License. See LICENSE for details.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages