chkaufmann 17 Posted August 5, 2023 I'm using Superobjects to handle JSON data. Now I have to handle a result, where there are identifiers with dots: { "splash.annually": "normal" } This library cannot handle this data because it looks at "splash.annually" as path. Can somebody recommend me another library? What I like with Superobjects: It is fast and it offers reference counted object handling using interfaces. Regards Christian Share this post Link to post
ertank 27 Posted August 6, 2023 I do not know about Superobjects but Delphi standard json library can do following uses System.JSON, System.Generics.Collections; procedure TForm1.Button1Click(Sender: TObject); const JsonText = '{ "splash.annually": "normal" }'; var Json: TJSONValue; begin Json := TJSONObject.ParseJSONValue(JsonText, False, False); if Json <> nil then begin if Json.FindValue('["splash.annually"]') <> nil then begin ShowMessage(Json.FindValue('["splash.annually"]').AsType<string>); end; Json.Free(); end; end; Share this post Link to post
mytbo 5 Posted August 6, 2023 18 hours ago, chkaufmann said: Can somebody recommend me another library? In mORMot there are many ways to process JSON. mORMot is at least factor 5 faster than your current solution and more than 20 times faster than Delphi's own classes. A few of several possibilities are: var v: Variant; begin v := _JsonFast('{"splash.annually": "normal"}'); ShowMessage(v.Value('splash.annually')); var doc: TDocVariantData; begin doc.InitJson('{"splash.annually": "normal"}'); ShowMessage(doc.S['splash.annually']); I have published an article on this topic here (forum Delphi-PRAXIS). Here is the translation into English with Google Translator. The result is not perfect (rather not so good), also some formatting is destroyed, but it is readable. With best regards Thomas Share this post Link to post
Bob Devine 11 Posted August 6, 2023 I use the mORMot solution for my REST stuff but for desktop applications I use this excellent library: https://github.com/paolo-rossi/delphi-neon It was the best library when I tested a couple years back for handling nested objects - had no problems with it. Cheers, Bob Share this post Link to post
mytbo 5 Posted August 6, 2023 (edited) 1 hour ago, Bob Devine said: It was the best library when I tested a couple years back for handling nested objects... What problems did you have with nested objects? mORMot can serialize almost anything to JSON. And if you use class TSynAutoCreateFields, you don't have to create or destroy the child object(s) yourself. It is enough to write the following: type {$M+} TSubItem = class(TObject) private FSubValue: RawUtf8; published property SubValue: RawUtf8 read FSubValue write FSubValue; end; {$M-} TItem = class(TSynAutoCreateFields) private FValue: RawUtf8; FSubItem: TSubItem; published property Value: RawUtf8 read FValue write FValue; property SubItem: TSubItem read FSubItem; end; var item: TItem; list: TObjectList; begin list := TObjectList.Create; try for var i: Integer := 0 to 1000 do begin item := TItem.Create; item.Value := StringToUtf8('value' + i.ToString); item.SubItem.SubValue := StringToUtf8('subValue' + i.ToString); list.Add(item); end; ObjectToJsonFile(list, '_listData.json'); finally list.Free; end; With best regards Thomas Edited August 6, 2023 by mytbo Share this post Link to post
Fr0sT.Brutal 900 Posted August 7, 2023 On 8/5/2023 at 10:48 PM, chkaufmann said: This library cannot handle this data because it looks at "splash.annually" as path Probably there is some option to not use paths or redefine path delimiters? Share this post Link to post
Bob Devine 11 Posted August 7, 2023 12 hours ago, mytbo said: What problems did you have with nested objects? To be honest I can't remember. It was about 4 years ago and no doubt mORMot will now have it sorted out 🙂 I use JSON for config files on the desktop and at the time Neon was the only one that coped with the complex configs I was using. I use mORMot JSON for everything else where performance is important (I never tested Neon for performance). Cheers, Bob Share this post Link to post