Jump to content
RDP1974

which JSON library

Recommended Posts

hi,
can I ask your opinion about this JSON library to adopt?

As much as there are good repositories for Delphi,
in the last period I feel comfortable with this JsonTools (I handled all the blobs correctly from many devices where other libraries gave me errors in parsing)

https://www.getlazarus.org/json/
https://www.getlazarus.org/json/tests/
(all test passed)
btw. I am a loyal Delphi customer, I don't want to advertise Lazarus 🙂

 

Share this post


Link to post

I am not one to tell you what you should or should not use... If you are familiar with it and works in the Delphi environment for you then go for it.  I also do not have any experience in using the library you mentioned. The test results appear impressive.

 

My own perspective is that is the tool already has the things I am looking for, I defer to those. In this instance, it would be :

 

https://docwiki.embarcadero.com/RADStudio/Athens/en/JSON

 

but if that does not meet your needs then ... 

Share this post


Link to post

Personal biais: the mORMot 2 Open Source framework has a very efficient JSON library, and several ways to use it:

- from RTTI, using classes, records, collections, dynamic arrays, mORMot generics...
- from variants, and a custom "document" variant type to store JSON objects or arrays...
- from high-level IDocList / IDocDict holders.

 

See https://blog.synopse.info/?post/2024/02/01/Easy-JSON-with-Delphi-and-FPC

 

It is perhaps the fastest library available, working on Delphi and FPC, with unique features, like:

  list := DocList('[{"a":10,"b":20},{"a":1,"b":21},{"a":11,"b":20}]');
  // sort a list/array by the nested objects field(s)
  list.SortByKeyValue(['b', 'a']);
  assert(list.Json = '[{"a":10,"b":20},{"a":11,"b":20},{"a":1,"b":21}]');

  // create a dictionary from key:value pairs supplied from code
  dict := DocDict(['one', 1, 'two', 2, 'three', _Arr([5, 6, 7, 'huit'])]);
  assert(dict.Len = 3); // one dictionary with 3 elements
  assert(dict.Json = '{"one":1,"two":2,"three":[5,6,7,"huit"]}');
  // convert to JSON with nice formatting (line feeds and spaces)
  Memo1.Caption := dic.ToString(jsonHumanReadable);

  // integrated search / filter
  assert(DocList('[{ab:1,cd:{ef:"two"}}]').First('ab<>0').cd.ef = 'two');

 

  • Like 1

Share this post


Link to post

I also did this small test (parsing, path retrieve) over Grijjy.Bson, NesLib.Json, System.Json

of course this test is not exhaustive, anyway Ahausladen is the fastest

(D12.2 x64 Win11 24h2)

Share this post


Link to post
On 10/12/2024 at 10:07 PM, Arnaud Bouchez said:

Personal biais: the mORMot 2 Open Source framework has a very efficient JSON library, and several ways to use it:

- from RTTI, using classes, records, collections, dynamic arrays, mORMot generics...
- from variants, and a custom "document" variant type to store JSON objects or arrays...
- from high-level IDocList / IDocDict holders.

 

See https://blog.synopse.info/?post/2024/02/01/Easy-JSON-with-Delphi-and-FPC

 

It is perhaps the fastest library available, working on Delphi and FPC, with unique features, like:


  list := DocList('[{"a":10,"b":20},{"a":1,"b":21},{"a":11,"b":20}]');
  // sort a list/array by the nested objects field(s)
  list.SortByKeyValue(['b', 'a']);
  assert(list.Json = '[{"a":10,"b":20},{"a":11,"b":20},{"a":1,"b":21}]');

  // create a dictionary from key:value pairs supplied from code
  dict := DocDict(['one', 1, 'two', 2, 'three', _Arr([5, 6, 7, 'huit'])]);
  assert(dict.Len = 3); // one dictionary with 3 elements
  assert(dict.Json = '{"one":1,"two":2,"three":[5,6,7,"huit"]}');
  // convert to JSON with nice formatting (line feeds and spaces)
  Memo1.Caption := dic.ToString(jsonHumanReadable);

  // integrated search / filter
  assert(DocList('[{ab:1,cd:{ef:"two"}}]').First('ab<>0').cd.ef = 'two');

 

Hi, is it possible to use a retrieval path method for example on a list with multiple arrays inside?
Many libraries offer a subset of https://goessner.net/articles/JsonPath/ for simple retrievals.

 

Share this post


Link to post

I've got thousands of large JSONS in the same format (like with intake data for many persons..) each with many objects

and array's where the people wanted to do searching.

I tried many Delphi JSON programming libraries but ended up by adding all the plain JSONS as records in the

MSSQL database and wrote a SQL-View using the "OPENJSON" rowset function

 

Now I can do:

Select * FROM [View_JSON] where field=value

 

Even better.. You can just do joins with "normal" tables..

Select * FROM [View_JSON_] left join myNormalTable on [View_JSON].field=myNormalTable.field=value

 

and the speed.? :classic_biggrin::classic_tongue:

Edited by Die Holländer

Share this post


Link to post

Different use cases will suit different libraries. You gave no indication of what your motivations and goals are. 

Share this post


Link to post

eg. a typical TCP chat client server, with a common protocol as discord or whatsapp or old msn.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×