Well, when I get my hands on it, I'll do a comparative benchmark.
I compared the speed of 4 libraries, including ToyJson3 from MQL5Book. As a sample json I took Binance's response to "exchangeInfo" with the size of 768 Kb. When the library reads it from a string, it is parsed in its entirety, then I select one symbol and read all its data. In a loop 100 times.
MetaTrader 5 x64 build 5370 started for MetaQuotes Ltd. Windows 10 build 19045, 4 x AMD Ryzen 3 PRO 3200 GE w/ Radeon Vega, AVX2, 6 / 13 Gb memory, 241 / 427 Gb disk, UAC, GMT+3 cpu='AVX2 + FMA3'
Result (query processing time):
99.5 ms - JAson 1.12(https://www.mql5.com/en/code/13663)
85.5 ms - JAson 1.13
46.9 ms - ToyJson3 (https://www.mql5.com/ru/forum/459079/page4#comment_57805801)
41 ms - JSON(https://www.mql5.com/en/code/53107)
1132 ms - JsonNode (this library)
38 ms - my implementation based on JSON
PS: Once upon a time another, very stripped down, library seemed to pop up here. But I've lost track of it.
PPS: I don't publish the script for measuring. The code is in a completely unsightly form.
I compared the speed of 4 libraries, including ToyJson3 from MQL5Book. As a sample json I took Binance's response to "exchangeInfo" with the size of 768 Kb. When the library reads it from a string, it is parsed in its entirety, then I select one symbol and read all its data. In a loop 100 times.
Result (query processing time):
99.5 ms - JAson 1.12(https://www.mql5.com/en/code/13663)
85.5 ms - JAson 1.13
46.9 ms - ToyJson3 (https://www.mql5.com/ru/forum/459079/page4#comment_57805801)
41 ms - JSON(https://www.mql5.com/en/code/53107)
1132 ms - JsonNode (this library)
38 ms - my implementation based on JSON
PS: Once upon a time another, very stripped down, library seemed to pop up here. But I've lost track of it.
PPS: I don't publish the script for measuring. The code is in a completely unsightly form.
Could you post the json string or file please?
https://fapi.binance.com/fapi/v1/exchangeInfo
https://eapi.binance.com/eapi/v1/exchangeInfo
778 KB (796,729 bytes).
Could you post the json string or file please?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Check out the new article: Mastering JSON: Create Your Own JSON Reader from Scratch in MQL5.
Experience a step-by-step guide on creating a custom JSON parser in MQL5, complete with object and array handling, error checking, and serialization. Gain practical insights into bridging your trading logic and structured data with this flexible solution for handling JSON in MetaTrader 5.
In this article, we aim to fill that gap by demonstrating how to create your own JSON reader in MQL5. Along the way, we’ll explore the fundamental concepts of parsing JSON, walking through the creation of a flexible class structure capable of handling different JSON element types (like objects, arrays, strings, numbers, booleans, and null values). Our end goal is to empower you to comfortably parse JSON strings and access or modify the data within them, all from the convenience of your MetaTrader 5 environment.
We will follow a structure similar to what we’ve seen in other MQL5-related articles but with a focus specifically on JSON parsing and usage. This single article will be divided into five main sections: an introduction (the one you’re reading now), a deeper dive into the fundamentals of JSON and how it fits within MQL5, a step-by-step guide to building a basic JSON parser from scratch, an exploration of advanced features for JSON handling, and finally a comprehensive code listing plus concluding thoughts.
Author: Sahil Bagdi