Android JSON Parsers Comparison
There are bunch of json parsers. Recently I discovered ason. Also I heard about moshi but not used it. So I wanted to compare them.
List of parsers to compare: gson 2.8.0, jackson 2.0.1, moshi 1.4.0, ason 1.1.0.
I found one worthy related article from 2015. It’s compares old versions of gson and jackson and it does not cover moshi and ason.
how I am going to test
I experimented on parsing small (6kb) and big (973kb, slow page!) jsons.
Small JSON consists of list of small objects. Small object consists of 4 simple fields and one list.
Big JSON consists of list of big objects. Big object consists of 19 simple fields and four lists.
I recorded 2 parameters: parsing time and number of GC calls while parsing. Less is better for both.
To track GC calls I used my friends’ GC calls tracker.
testing methodology
- Open app.
- Run parsing (for example small JSON with gson) 4 times.
- Throw away first result.
- Find average value for 2–4 runs.
- Close app and remove app from recent list.
methods / fields count
It’s worth to mention, due to 65k limit:
| methods count | fields count
-------------------------------------
gson | 1030 | 405
moshi | 535 | 238
jackson | 6724 | 1756
ason | 89 | 6
small json parsing
Let’s parse small JSON on 4.4 emulator:
4.4.2 | time / gc
-------------------
gson | 1124 / 76
jackson | 840 / 36
moshi | 2198 / 38
ason | 3343 / 193
6.0.1 real device (lenovo vibe x3):
6.0.1 | time / gc
--------------------
gson | 1024 / 3
jackson | 913 / 1
moshi | 2092 / 2
ason | 6225 / 14
big JSON parsing
Parsing big JSON on 4.4.2 emulator:
4.4.2 | time / gc
--------------------
gson | 1837 / 63
jackson | 1536 / 41
moshi | 2978 / 87
ason | 1745 / 88
6.0.1 real device (lenovo vibe x3):
6.0.1 | time / gc
--------------------
gson | 1988 / 5
jackson | 1902 / 4
moshi | 4611 / 9
ason | 1373 / 4
Let’s stop here. Ason is far more better than jackson. Moshi shows worst result. I also tried 5.1 emulator and another 6.0 emulator and get similar time ratio. 7.0 emulator gets me another picture:
7.0 | time / gc
--------------------
gson | 505 / 9
jackson | 327 / 6
moshi | 692 / 13
ason | 862 / 17
So ason performance varies between platforms, from fastest to slowest.
conclusion
jackson:
pros: fasters, triggers GC least, most customazible
cons: 6.7k methods (can be reduced by Proguard), API not so friendly
gson:
pros: fast enough, most popular (10k stars on github), pretty API, small
cons: relatively slow, trigger GC relatively more
There is no reasons for me to use moshi or ason based on this comparation: they are slower almost in each test.