#1 2024-02-02 16:53:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

IDocList/IDocDict JSON for Delphi and FPC

Since years, our Open Source mORMot framework offers several ways to work with any kind of runtime arrays/objects documents defined, e.g. via JSON, with a lot of features, and very high performance.

Our TDocVariant custom variant type is a powerful way of working with such schema-less data, but it was found confusing by some users.
So we developed a new set of interface definitions around it, to ease its usage, without sacrificing its power. We modelized them around Python Lists and Dictionaries, which is proven ground - with some extensions of course.

This is the forum discussion topic for our blog article:
https://blog.synopse.info/?post/2024/02 … hi-and-FPC

Offline

#2 2024-02-02 19:19:12

Márcio Baroni
Member
From: Brasil
Registered: 2015-10-07
Posts: 34

Re: IDocList/IDocDict JSON for Delphi and FPC

Congratulations Arnoud
I always had difficulty working with TDocVariant/TDocVariantData
Very good...

Offline

#3 2024-02-02 19:42:32

mdbs99
Member
From: Rio de Janeiro, Brazil
Registered: 2018-01-20
Posts: 139
Website

Re: IDocList/IDocDict JSON for Delphi and FPC

Nice improvements!

Note that those both lines compile and run with the antique Delphi 7 compiler - who said the pascal language was not expressive, even back in the day?

And I still have mine, which still working on production nowadays!
Thanks.

Offline

#4 2024-02-02 23:51:05

vs
Member
Registered: 2019-10-21
Posts: 36

Re: IDocList/IDocDict JSON for Delphi and FPC

Thank you Arnaud for your daily work and for sharing your knowledge and experience with us!
Great job!

Regarding your question in the blog article about the magic number 1.0594631 is the twelfth root of 2, if I'm not mistaken.
And your hint about programming music suggests that there are 12 semitones in an octave and each semitone differs from its neighbors by 1.0594631 (the twelfth root of 2).
I guessed? )))))

Last edited by vs (2024-02-02 23:52:14)

Offline

#5 2024-02-03 07:06:32

okoba
Member
Registered: 2019-09-29
Posts: 118

Re: IDocList/IDocDict JSON for Delphi and FPC

I am trying the blog post sample and I can not find First() function in the sample code.

Offline

#6 2024-02-03 09:03:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: IDocList/IDocDict JSON for Delphi and FPC

@Marcio
Thanks. Hope it will be useful.

@Marco
You know where it was meant to appear next: in the TIS grid.

@vs
You are right: this is to compute semi-tones, so to compute the notes frequencies. wink

@okaba
https://github.com/synopse/mORMot2/comm … 5468788de9

Offline

#7 2024-02-03 10:19:28

okoba
Member
Registered: 2019-09-29
Posts: 118

Re: IDocList/IDocDict JSON for Delphi and FPC

Thank you!

Offline

#8 2024-02-05 19:25:09

mdbs99
Member
From: Rio de Janeiro, Brazil
Registered: 2018-01-20
Posts: 139
Website

Re: IDocList/IDocDict JSON for Delphi and FPC

ab wrote:

@Marco
You know where it was meant to appear next: in the TIS grid.

Sure wink

Offline

#9 2024-02-06 06:55:34

squirrel
Member
Registered: 2015-08-13
Posts: 155

Re: IDocList/IDocDict JSON for Delphi and FPC

Thank you so much for this @ab!

Besides being very very useful, it also makes the code more readable and understandable, especially when someone unfamiliar with mORMot needs to work on/review our code. 

High-level wrappers like these makes it possible for the power of mORMot to be fully used without needing to know the technical details of everything that is possible, but undiscoverable in this great framework.

Offline

#10 2024-02-06 07:32:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: IDocList/IDocDict JSON for Delphi and FPC

@squirrel
Yes, you are right, that was exactly the goal: make the framework more usable in practice.

Yesterday, I have added compatibility of IDocList/IDocDict with SOA interface-based services parameters.
I guess they make working with JSON in SOA pretty simple.
Today, I will implement ISerialiazable/TSerializable to let any class + interface also be par of SOA parameters. Also trying to make the framework use easier.

Offline

#11 2024-03-23 11:54:26

Coldzer0
Member
From: ::1
Registered: 2018-08-31
Posts: 35
Website

Re: IDocList/IDocDict JSON for Delphi and FPC

Hello,

I recently started using IDocDict and IDocList, and everything works well.
But there's a small thing I can't figure out.

Is there a way to read a value from a JSON path, for example, this data

{"@type":"updateNewMessage","message":{"@type":"message","id":123456789,"sender_id":{"@type":"messageSenderUser","user_id":123456789},"chat_id":123456789,"is_outgoing":false,"is_pinned":false,"can_be_edited":false,"can_be_forwarded":true,"can_be_replied_in_another_chat":true,"can_be_saved":true,"can_be_deleted_only_for_self":true,"can_be_deleted_for_all_users":true,"can_get_added_reactions":false,"can_get_statistics":false,"can_get_message_thread":false,"can_get_read_date":false,"can_get_viewers":false,"can_get_media_timestamp_links":false,"can_report_reactions":false,"has_timestamped_media":true,"is_channel_post":false,"is_topic_message":false,"contains_unread_mention":false,"date":1711194238,"edit_date":0,"unread_reactions":[],"message_thread_id":0,"self_destruct_in":0.000000,"auto_delete_in":0.000000,"via_bot_user_id":0,"author_signature":"","media_album_id":"0","restriction_reason":"","content":{"@type":"messageText","text":{"@type":"formattedText","text":"/start","entities":[{"@type":"textEntity","offset":0,"length":6,"type":{"@type":"textEntityTypeBotCommand"}}]}}}}

Can I do a reading using the full path

function ReadMsg(JSONStr : String) : String;
var
    JSON: IDocDict;
begin
    result := '';
    if IsValidJson(JSONStr) then
    begin
      JSON := DocDict(JSONStr); 
      result := JSON.S['message.content.text.text']; // Can I do that using mormot?
    end;    
end;

And for the Exists method

if JSON.Exists('message.content.text') then

Thanks.

Last edited by Coldzer0 (2024-03-23 12:03:35)


Mac, Windows, Linux
FPC Trunk, Lazarus Trunk, Delphi 12.x Latest

Offline

#12 2024-03-27 18:35:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: IDocList/IDocDict JSON for Delphi and FPC

There is the IDocDict.PathDelim property to enable nested objects path.
It is disabled by default for performance reasons, and because a property name may have a dot or a slash in its own text, so it would make a lot of confusion.

Sorry for the late replay.

Offline

Board footer

Powered by FluxBB