Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JSON Query Comparison
(version: 9)
Comparison of various JSON Querying libraries
Comparing performance of:
jsonata vs simple vs jspath vs jmespath vs control vs jspath+predicates vs meta-index vs meta-nameonly vs meta-flatten
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" language="javascript" src="https://cdn.jsdelivr.net/npm/jsonata@1.5.4/jsonata-es5.min.js"></script> <script type="text/javascript" language="javascript" src="https://cdn.jsdelivr.net/npm/jspath@0.4.0/jspath.min.js"></script> <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jmespath/0.15.0/jmespath.min.js"></script> <script type="text/javascript" language="javascript" src="https://prototype.imin.co/eventseries-sample.js"></script> <script type="text/javascript" language="javascript" src="http://meta.imin.co/v2.js"></script>
Script Preparation code:
var get = p => o => p.reduce((xs, x) => { if (Array.isArray(xs)) { return xs.map(get([x])).filter(y => y !== null).flat(); } else { return (xs && xs[x]) ? xs[x] : null; } }, o); function flattenCollection(collectionIndex) { if (collectionIndex.type === 'imin:CollectionIndex') { return Object.entries(collectionIndex['imin:index']).reduce(function(map, [k,v]) { map[k] = flattenCollection(v); return map; }, {}); } else if (collectionIndex.type === 'imin:Collection') { return collectionIndex['imin:item'].reduce(function(map, item) { map[item.id] = item; return map; }, {}); } else { return collectionIndex; } }
Tests:
jsonata
var jsonataResult = jsonata('subEvent.offers.acceptedPaymentMethod').evaluate(result).join('<br />');
simple
var simpleResult = get(['subEvent','offers','acceptedPaymentMethod'])(result).join('<br />');
jspath
var jsPathResult = JSPath.apply('.subEvent.offers.acceptedPaymentMethod', result).join('<br />');
jmespath
var jmespathResult = jmespath.search(result, 'subEvent[].offers[].acceptedPaymentMethod[]').join('<br />');
control
result.subEvent.map(s => s.offers.map(o => o.acceptedPaymentMethod)).flat(2).join('<br />')
jspath+predicates
var jsPathResult = JSPath.apply('."imin:aggregateOffer".publicAdult{.price > 0 && .priceCurrency > "."}[-1]', result);
meta-index
var jsPathResult = JSPath.apply('."imin:index"(.subClass | .enumeration).."imin:item"', window.imin.v2.meta);
meta-nameonly
var jsPathResult = JSPath.apply('."imin:index"(.subClass | .enumeration)..name', window.imin.v2.meta);
meta-flatten
var result = flattenCollection(window.imin.v2.meta);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (9)
Previous results
Fork
Test case name
Result
jsonata
simple
jspath
jmespath
control
jspath+predicates
meta-index
meta-nameonly
meta-flatten
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
The provided JSON represents a set of benchmark tests for comparing different libraries and approaches to query JSON data in JavaScript. **Library Overview** 1. **jsonata**: A JSON querying language that allows you to query JSON data using a simple syntax. 2. **simple**: A custom implementation by the creator of MeasureThat.net, which uses a reduce function to traverse the JSON data. 3. **jspath**: A library inspired by XPath (XML Path Language) that allows you to query JSON data using a similar syntax to XML. 4. **jmespath**: A JSON-specific variant of XPath that is optimized for querying JSON data. **Library Comparison** Each test compares the performance of one or more libraries and approaches when querying JSON data. The results are represented as a series of objects, each containing information about the benchmark run, such as: * `TestName`: The name of the benchmark test. * `RawUAString`: The User Agent string reported by the browser during the benchmark run. * `Browser`, `DevicePlatform`, and `OperatingSystem`: Information about the browser and device used during the benchmark run. * `ExecutionsPerSecond`: The number of executions per second for each library or approach. **Approach Comparison** The tests compare different approaches to querying JSON data, including: 1. **jspath**: Uses a syntax similar to XML XPath to query JSON data. 2. **jmespath**: Optimized for querying JSON data using a syntax inspired by XPath. 3. **simple**: A custom implementation by the creator of MeasureThat.net, which uses a reduce function to traverse the JSON data. 4. **jsonata**: Uses a simple syntax to query JSON data. **Key Insights** * jmespath and jspath are optimized for querying JSON data and outperform the other libraries in many cases. * jsonata is relatively slow compared to the other two, but still performs well. * The custom implementation by MeasureThat.net (simple) is slower than jmespath and jspath. Overall, these benchmarks provide a comprehensive comparison of different libraries and approaches for querying JSON data in JavaScript, allowing developers to choose the best option for their specific use case.
Related benchmarks:
Native map & filter vs reduce with push and desctructuring (10 000 samples )
flatMap vs reduce filtering performance
Reduce vs map with empty filter
flatMap vs reduce vs loop filtering vs filter/map performance
Reduce Push vs. flatMap vs 123
Comments
Confirm delete:
Do you really want to delete benchmark?