Recent

Author Topic: [solved, great solution] json reading - no idea where to start  (Read 1004 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1303
After a very productive time with ChatGPT, I tried to work with json.
It talks me into complete nonsense since days. Nothing works.

What I want looks quite easy to me.
Never the less I never did it before.

I grabbed a json file, which looks really nice, if I double-click it and view it in notepad ++
I attach it.

And I have an array TKurse, which "looks the same":
Code: Pascal  [Select][+][-]
  1. Type TEineKontraktZeile = packed Record  
  2.      Datum: TDateTime;
  3.      open, high, low, close, Volume: double;
  4.         end;
  5. Type TKurse  = array of TEineKontraktzeile;    

So, it shall be easy to take the data from one and fill it in the other?
However it does not work and does not work.

As I worked never before with json, it starts with the basic question, if I have to transform it.
ChatGPT said, I shall make it a string. I did by TstingList and stringList.saveAs made it a file.
So there is the option to work with the json file or the saved stringList of it.
Please hint me!

The next riddle are the meta-data. Sure, we all can read and understand them.
Is there a way that the computer reads them and know, what to do?

What I need is a basic demo, how json works.
ChatGPT made a lot of suggestions for source code and I ended up with compiler warnings "unknown..." something.

So the basic demo shall hint me as well, what to write best into the uses clauses and may be a class or unit to work with best.

thanks
« Last Edit: April 08, 2025, 11:10:22 am by Nicole »

Nicole

  • Hero Member
  • *****
  • Posts: 1303
Re: json reading - no idea where to start
« Reply #1 on: April 02, 2025, 07:35:26 pm »
attach

cdbc

  • Hero Member
  • *****
  • Posts: 2628
    • http://www.cdbc.dk
Re: json reading - no idea where to start
« Reply #2 on: April 02, 2025, 08:02:51 pm »
Hi
Have you had a look in "C:\...?...\fpcsrc/packages/fcl-json/examples/"
That's where you find the built-in FPC JSON classes and units:
Code: Pascal  [Select][+][-]
  1. uses ..., fpjson;
should put the lazarus editor on track, for a start...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

wp

  • Hero Member
  • *****
  • Posts: 13361
Re: json reading - no idea where to start
« Reply #3 on: April 02, 2025, 08:06:32 pm »
There is also a wiki on json: https://wiki.freepascal.org/fcl-json

And the article "Web data formats in Lazarus/FPC" by Michael Van Canneyt contains a chapter on json: https://www.freepascal.org/~michael/articles/webdata/webdata.pdf
« Last Edit: April 02, 2025, 08:16:03 pm by wp »

Renat.Su

  • Sr. Member
  • ****
  • Posts: 253
    • Renat.Su
Re: json reading - no idea where to start
« Reply #4 on: April 02, 2025, 09:14:25 pm »
I think this article is that you want https://wiki.lazarus.freepascal.org/Streaming_JSON
But it is about class instances not record.

wp

  • Hero Member
  • *****
  • Posts: 13361
Re: json reading - no idea where to start
« Reply #5 on: April 03, 2025, 12:09:33 am »
Here is a small demo reading your json file and displaying it in a stringgrid and a chart. Note that the analysis of the file is not generally valid here, it is tuned to your data file for simplicity.

Nicole

  • Hero Member
  • *****
  • Posts: 1303
Re: json reading - no idea where to start
« Reply #6 on: April 03, 2025, 11:31:53 am »
Thank you so very much WP!
This code does all, what I dreamed of!

 

TinyPortal © 2005-2018