I found this JSON library, Neslib.Json, that looks interesting, and I'd like to play with it in WEB Core. But it does its parsing by keeping a cursor as a PChar and incrementing it to move through a string. I have not been able to get this to compile for WEB Core, and I'm curious if anybody might know of a port that doesn't use pointer math, but just an array with an index. Or even regex to parse things.
I tried using ChatGPT to rewrite it and wasted 3 hours because the 4o model SUCKS at working with code. The o3-mini model is far better, which I thought I was using; but if you try working in a Project, it switches to 4o and that's all you can use. (I have the Plus subscription, and cannot afford the one for $200/mo that gives you unrestricted access to everything. Maybe someone who does can try to have it do this.)
Why do you need a JSON library for working within TMS WEB Core in the first place? You can use JavaScript directly, usually without much effort? Or there are JSON helpers in TMS WEB Core that you can use as well. Lots of options right out of the box.
This blog post is already a bit dated, and I might have implemented a few of these differently given what I know now, but this might help get you oriented.
That guy did write a JS solution which could certainly be used with WEB Core apps.
I just find its approach to pathing to be a bit more intuitive (except his choice of '..' for recursive-descent because in most file system notations it refers to the parent of the current node. I think I'd pick a different character, like '!'.
There are three main units that were built in Delphi: (1) a JSON parser; (2) a path interpreter; and (3) an I/O unit.
Today I was able to get ChatGPT to help me rewrite them with the o3-mini-high model. I'm about to see if I can compile them and get them to work.
Have a look at the above paper and maybe take a look at his JS code and see what's required to make it work in WEB Core.
I'll post the Delphi code once I've got it working. Hopefully that won't take long.
Why not just use JavaScript directly, where you can do exactly what he's trying to do. No libraries needed, nothing to compile, no dependencies.
procedure TForm1.JSONTest;
var
data: String;
city: String;
begin
data := '{"people":[{"name":"person1","emails":["email1","email2"],"addresses":[{"street":"street1","city":"city1"}]}]}';
city := '';
asm
city = JSON.parse(data).people[0].addresses[0].city;
end;
console.log(city);
// outputs city1 to the console
end;
Probably a dozen other ways to do it as well, this is just an example of one.
Believe me, it is WAY more fun once your project is up and running and you're not down in the dirt trying to do the basic things. TMS WEB Core is pretty incredible. Previous incantations of Delphi-to-web tools always seemed to get tripped up by one thing or another. But now. Well. Everything is on the table. I'm going to write a post at some point this month showcasing just how far you can get without using anything but popular JS libraries and TMS WEB Core.
Are you referring to highlighting in the IDE editor or an error by the compiler?
It should NOT cause a compiler error. But the IDE LSP can't handle pas2js extensions such as JavaScript ASM blocks. Try to put this block within {$IFDEF PAS2JS} {$ENDIF} define.