You are not logged in.
Pages: 1
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
Congratulations Arnoud
I always had difficulty working with TDocVariant/TDocVariantData
Very good...
Online
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
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
I am trying the blog post sample and I can not find First() function in the sample code.
Offline
@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.
Offline
Thank you!
Offline
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
@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
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
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
Pages: 1