Recent

Author Topic: JSON authoring tools?  (Read 1052 times)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 699
JSON authoring tools?
« on: November 03, 2025, 12:53:03 am »
I haven't used JSON to do anything but save and restore filled-out Lazarus forms so this may be a foolish question, but here goes: 

I have a bunch of data that could be nicely saved and retrieved as JSON (name,value) pairs (or maybe (name,value,comment)triples), but putting the data into a JSON structure is tedious.  Are there any tools that make writing JSON less of a chore?  Something perhaps like a tool that would convert a string grid into a JSON file?

Khrys

  • Sr. Member
  • ****
  • Posts: 381
Re: JSON authoring tools?
« Reply #1 on: November 03, 2025, 06:53:56 am »
Are there any tools that make writing JSON less of a chore?

A decent text editor  :)

Thaddy

  • Hero Member
  • *****
  • Posts: 18703
  • To Europe: simply sell USA bonds: dollar collapses
Re: JSON authoring tools?
« Reply #2 on: November 03, 2025, 07:06:54 am »
Try the jsonviewer in the tools subdirectory of lazarus. It is not only a viewer, but also a composer.

Also, Lazarus lets you export a form to xml. You can subsequently use https://jsonformatter.org/xml-to-json to convert the to json.
Simple example for  TStringlist I found:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2. uses
  3.   Classes, fpjson, jsonparser;
  4.  
  5. function StringListToJSON(StringList: TStrings): TJSONObject;
  6. var
  7.   i: Integer;
  8.   JSONArray: TJSONArray;
  9. begin
  10.   JSONArray := TJSONArray.Create;
  11.   try
  12.     for i := 0 to StringList.Count - 1 do
  13.     begin
  14.       JSONArray.Add(StringList[i]);
  15.     end;
  16.    
  17.     Result := TJSONObject.Create;
  18.     Result.Add('data', JSONArray);
  19.   except
  20.     JSONArray.Free;
  21.     raise;
  22.   end;
  23. end;
  24.  
  25. function StringListToJSONObjectKeyValues(StringList: TStrings): TJSONObject;
  26. var
  27.   i: Integer;
  28. begin
  29.   Result := TJSONObject.Create;
  30.   try
  31.     for i := 0 to StringList.Count - 1 do
  32.     begin
  33.       Result.Add(StringList.Names[i], StringList.ValueFromIndex[i]);
  34.     end;
  35.   except
  36.     Result.Free;
  37.     raise;
  38.   end;
  39. end;
  40.  
  41. // Usage example:
  42. var
  43.   MyList: TStringList;
  44.   JSONData: TJSONObject;
  45. begin
  46.   MyList := TStringList.Create;
  47.   try
  48.     MyList.Add('Item 1=1');
  49.     MyList.Add('Item 2=2');
  50.     MyList.Add('Item 3=3');
  51.    
  52.     JSONData := StringListToJSONObjectKeyValues(MyList);
  53.     try
  54.       WriteLn(JSONData.FormatJSON); // Pretty printed JSON
  55.       // or
  56.       // WriteLn(JSONData.AsJSON);  // Compact JSON
  57.     finally
  58.       JSONData.Free;
  59.     end;
  60.   finally
  61.     MyList.Free;
  62.   end;
  63. end.
[editted TStringlist ---> TStrings.]

Outputs for KV version:
Code: Text  [Select][+][-]
  1. {
  2.   "Item 1" : "1",
  3.   "Item 2" : "2",
  4.   "Item 3" : "3"
  5. }

« Last Edit: November 03, 2025, 09:39:58 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

avk

  • Hero Member
  • *****
  • Posts: 825
Re: JSON authoring tools?
« Reply #3 on: November 03, 2025, 10:57:59 am »
I searched the Free Pascal and Lazarus Wiki for "json streaming"/"json serialization", and the choice turned out to be quite limited: the first and the second.

wp

  • Hero Member
  • *****
  • Posts: 13334

Thaddy

  • Hero Member
  • *****
  • Posts: 18703
  • To Europe: simply sell USA bonds: dollar collapses
Re: JSON authoring tools?
« Reply #5 on: November 03, 2025, 01:29:35 pm »
What I really do not understand is that people can not find fcl-json or lgenerics for that matter.
Both libraries are pretty straightforward to use and take minor effort.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 699
Re: JSON authoring tools?
« Reply #6 on: November 03, 2025, 03:41:01 pm »
Try the jsonviewer in the tools subdirectory of lazarus. It is not only a viewer, but also a composer.
...

That's just the sort of tool I was looking for.  Thank you very much.
I haven't tried the string list to JSON code yet -- appreciate the example to study though and will get to it sometime today.

Thaddy

  • Hero Member
  • *****
  • Posts: 18703
  • To Europe: simply sell USA bonds: dollar collapses
Re: JSON authoring tools?
« Reply #7 on: November 03, 2025, 06:21:50 pm »
Curt,

Make sure you compile it in release mode for now.
There are some small "issues" - not in functionality, but some things need to be addressed. (to quote cdbc: hihi)
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Xenno

  • New Member
  • *
  • Posts: 49
    • BS Programs
Re: JSON authoring tools?
« Reply #8 on: November 04, 2025, 05:57:25 am »
I created an app with Lazarus to edit JSON. It is for Windows.
If you wanna take a look:

BS JSON – Seamless JSON Editor with Data Tools
https://youtu.be/Ijjb_Qzb6WU?si=8ErhBmhET19K7SKw
Lazarus 4.0, Windows 10, https://www.youtube.com/@bsprograms

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 699
Re: JSON authoring tools?
« Reply #9 on: November 05, 2025, 03:31:45 am »
I created an app with Lazarus to edit JSON. It is for Windows.
If you wanna take a look:

BS JSON – Seamless JSON Editor with Data Tools
https://youtu.be/Ijjb_Qzb6WU?si=8ErhBmhET19K7SKw

Thanks for the link:  that's an impressive and very capable tool for professionals, with way more capability than I need in my simple projects.  Nice looking software! 

Xenno

  • New Member
  • *
  • Posts: 49
    • BS Programs
Re: JSON authoring tools?
« Reply #10 on: November 05, 2025, 07:00:32 am »
Thank you, Curt.

Just to share the technical, it's fully built with Lazarus using out-of-the-box Lazarus components and FreePascal units (virtual tree, synedit, fpjson, csvreadwrite). A little tweak for captionless form and apply BS PanelTrans's buttons.

Perhaps someday you need to use this app or inspire you to create more advance ones.   :)
Lazarus 4.0, Windows 10, https://www.youtube.com/@bsprograms

 

TinyPortal © 2005-2018