Hello,
I am going to receive a JSON file/message from RestfulAPI. I would like to parse the JSON in PASCAL for processing.
Does anyone know of library that I can use?
Appreciate your help.
JSON parser for VMS PASCAL Itanium
-
Topic author - Visitor
- Posts: 2
- Joined: Fri Apr 30, 2021 8:01 pm
- Reputation: 0
- Status: Offline
-
- Master
- Posts: 104
- Joined: Fri Jun 14, 2019 11:05 pm
- Reputation: 0
- Location: Goslar, Germany
- Status: Offline
- Contact:
Re: JSON parser for VMS PASCAL Itanium
There has been a thread about this a few months ago, see here. With Pascal declarations of the routines and perhaps a thin wrapper to convert strings any of the mentioned C libraries should be usable.
There is something wrong with everything that is popular.
(Charles Fort)
(Charles Fort)
-
- Master
- Posts: 336
- Joined: Fri Apr 17, 2020 7:31 pm
- Reputation: 0
- Location: Rhode Island, USA
- Status: Offline
- Contact:
Re: JSON parser for VMS PASCAL Itanium
I gave it a try.
How does this look?
How does this look?
Code: Select all
[inherit('pJSON')]
program test(input, output);
const
JSON = '[ { "no" : 1, "name" : "Alan A", "role" : "Manager" }, ' +
'{ "no" : 2, "name" : "Brian B", "role" : "Engineer" }, ' +
'{ "no" : 3, "name" : "Chris C", "role" : "Sales rep" } ]';
var
employees, employee, newemployee : cJSON_ptr;
i, no : integer;
s, name, role : pstr;
begin
(* iterate over all employees *)
employees := pJSON_Parse(JSON);
for i := 0 to pJSON_GetArraySize(employees) - 1 do begin
employee := pJSON_GetArrayItem(employees, i);
(* find no, name and role *)
no := pJSON_IntValue(pJSON_GetObjectItem(employee, 'no'));
name := pJSON_StringValue(pJSON_GetObjectItem(employee, 'name'));
role := pJSON_StringValue(pJSON_GetObjectItem(employee, 'role'));
(* print *)
writeln('no = ', no:1);
writeln('name = ', name);
writeln('role = ', role);
end;
(* add employee *)
newemployee := pJSON_CreateObject;
pJSON_AddItemToObject(newemployee, 'no', pJSON_CreateNumber(4));
pJSON_AddItemToObject(newemployee, 'name', pJSON_CreateString('Dave D'));
pJSON_AddItemToObject(newemployee, 'role', pJSON_CreateString('Intern'));
pJSON_AddItemReferenceToArray(employees, newemployee);
(* write out *)
s := pJSON_PrintUnformatted(employees);
writeln(s);
(* *)
pJSON_Delete(employees);
end.
If interest then I could make the pJSON.pas available.no = 1
name = Alan A
role = Manager
no = 2
name = Brian B
role = Engineer
no = 3
name = Chris C
role = Sales rep
[{"no":1,"name":"Alan A","role":"Manager"},{"no":2,"name":"Brian B","role":"Engineer"},{"no":3,"name":"Chris C","role":"Sales rep"}, {"no":4,"name":"Dave D","role":"Intern"}]
-
Topic author - Visitor
- Posts: 2
- Joined: Fri Apr 30, 2021 8:01 pm
- Reputation: 0
- Status: Offline
Re: JSON parser for VMS PASCAL Itanium
Hello arne_v,
Yes, please send me the pJSON.pas file.
Thank you for the suggestion. Does this psJSON.pas also handle nested JSON file?
Yes, please send me the pJSON.pas file.
Thank you for the suggestion. Does this psJSON.pas also handle nested JSON file?
-
- Master
- Posts: 336
- Joined: Fri Apr 17, 2020 7:31 pm
- Reputation: 0
- Location: Rhode Island, USA
- Status: Offline
- Contact:
Re: JSON parser for VMS PASCAL Itanium
https://www.vajhoej.dk/arne/opensource/ ... c-v0_1.zip
cJSON supports what it supports.
I have made Pascal stubs for most of the functions, but there are still a few missing.
If you need some of the missing stuff just ping me and I will see if I can add it.
cJSON supports what it supports.
I have made Pascal stubs for most of the functions, but there are still a few missing.
If you need some of the missing stuff just ping me and I will see if I can add it.