Recent

Author Topic: [Solved] Json path search  (Read 356 times)

loaded

  • Hero Member
  • *****
  • Posts: 838
[Solved] Json path search
« on: April 25, 2024, 10:59:45 am »
Hi All,
I access the relevant data in the Json process as follows;
Code: Pascal  [Select][+][-]
  1. ...
  2. var
  3. json_mmx: TJSONData;
  4. ...
  5. json_mmx.FindPath('Fop').FindPath('Cdp').AsString;
  6.  

This, Is there a method I can use like this?
Code: Pascal  [Select][+][-]
  1. json_mmx.FindPath('Fop.Cdp').AsString;
« Last Edit: April 25, 2024, 01:02:37 pm by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Zvoni

  • Hero Member
  • *****
  • Posts: 2362
Re: Json path search
« Reply #1 on: April 25, 2024, 11:56:31 am »
it helps reading the documentation.......
https://www.freepascal.org/docs-html/fcl/fpjson/tjsondata.findpath.html
Quote
Obviously, this can be combined:

Var   
  D,E : TJSONData;
       
begin
  D:=TJSONObject.Create(['Age',23,
                         'Names', TJSONObject.Create([
                             'LastName','Rodriguez',
                             'FirstName','Roberto'])]);
  E:=D.FindPath('Names.LastName');
  Writeln(E.AsJSON);   
end.

And mixed:

var   
  D,E : TJSONData;
       
begin
  D:=TJSONObject.Create(['Children',
       TJSONArray.Create([
         TJSONObject.Create(['Age',23,
                             'Names', TJSONObject.Create([
                               'LastName','Rodriguez',
                               'FirstName','Roberto'])
         ]),
         TJSONObject.Create(['Age',20,
                             'Names', TJSONObject.Create([
                                   'LastName','Rodriguez',
                                   'FirstName','Maria'])
        ])
      ])
     ]);
  E:=D.FindPath('Children[1].Names.FirstName');
  Writeln(E.AsJSON);
end. 
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

loaded

  • Hero Member
  • *****
  • Posts: 838
Re: Json path search
« Reply #2 on: April 25, 2024, 01:02:25 pm »
Thank you very much for your answer, Zvoni:-[
it helps reading the documentation.......
https://www.freepascal.org/docs-html/fcl/fpjson/tjsondata.findpath.html

I tried it in the morning but I couldn't get it to work. It's good that it's working now. I think I made a very amateur mistake...

« Last Edit: April 25, 2024, 01:06:08 pm by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018