PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Loading a json pre version 11  (Read 897 times)

michaelgreer

  • Diamond Member
  • *****
  • Posts: 129
    • View Profile
Loading a json pre version 11
« on: July 01, 2022, 02:39:07 PM »
All,  I developed a routine to retrieve JSON data from an API and, developing at 11.5, used the dim load array$[all]=json$.  My customer is running at 9.x and this feature is not available. Does anyone have a routine to load or parse a json.  I have parsing ability, but it isn't foolproof.

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Loading a json pre version 11
« Reply #1 on: July 01, 2022, 08:30:08 PM »
Might it not be simpler to just upgrade the account. 

Not only would that provide you access to the JSON parser, but all the other features and enhancements in a newer version.  PxPlus V9 is over 10 years old.
 
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

michaelgreer

  • Diamond Member
  • *****
  • Posts: 129
    • View Profile
Re: Loading a json pre version 11
« Reply #2 on: July 02, 2022, 08:15:47 AM »
Mike, it would it need be simpler were not Infor in the mix.  I think the federal government takes lessons in arcane bureaucracy from them  :).

Stéphane Devouard

  • Diamond Member
  • *****
  • Posts: 122
  • PxPlus guru with skills in PHP, JS, C#, Java
    • View Profile
    • Stéphane's Web Resume
Re: Loading a json pre version 11
« Reply #3 on: July 03, 2022, 03:54:38 AM »
Michael (Greer)

If this is on Windows, you can use an ActiveX/COM object to parse the JSON
The libraries from Chilkat software are good -- we used the Chilkat ZIP at a prior job, long before ZIP was directly supported by PxPlus
You just download and install their library, and register it as a ActiveX/COM class (it's all documented)
On this page : https://www.chilkatsoft.com/refdoc/activex.asp
Take a look at the documentation for the JsonObject and JsonArray classes

You also have example code for a bunch of development languages. VB6 is usually the easiest to translate to ProvideX.
https://www.example-code.com/vb6/json_array_of_objects.asp

Here is this code translate to PxPlus
Code: [Select]

0001 !
0002 BEGIN
0003 !
0004 LET JSON$="{""employees"":[{""firstName"":""John"", ""lastName"":""Doe""},{""firstName"":""Anna"", ""lastName"":""Smith""},{""firstName"":""Peter"",""lastName"":""Jones""}]}"
0005 !
0006 DEF OBJECT JSON,"Chilkat_9_5_0.JsonObject"
0007 !
0008 JSON'LOAD(JSON$)
0009 !
0010 LET EMPLOYEES=JSON'ARRAYOF("employees")
0011 DEF OBJECT EMPLOYEES
0012 !
0013 LET EMPLOYEES_COUNT=EMPLOYEES'SIZE
0014 LET EMPLOYEE_NR=0
0015 WHILE EMPLOYEE_NR<EMPLOYEES_COUNT
0016 !
0017 LET EMPLOYEE=EMPLOYEES'OBJECTAT(EMPLOYEE_NR)
0018 DEF OBJECT EMPLOYEE
0019 !
0020 PRINT EMPLOYEE'STRINGOF$("firstName")," ",EMPLOYEE'STRINGOF$("lastName")
0021 !
0022 DROP OBJECT EMPLOYEE,ERR=*NEXT
0023 EMPLOYEE_NR++
0024 WEND
0025 !
0026 DROP OBJECT EMPLOYEES,ERR=*NEXT
0027 DROP OBJECT JSON,ERR=*NEXT
0028 !
0029 STOP

And this is the result :
Code: [Select]
->run
John Doe
Anna Smith
Peter Jones
->

And the best news : these two classes do not require you to purchase a license from Chilkat, they are free to use :)

Hope this helps !
« Last Edit: July 03, 2022, 04:07:25 AM by Stéphane Devouard »
Stéphane Devouard
Portfolio | Work

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Loading a json pre version 11
« Reply #4 on: July 04, 2022, 01:41:01 PM »
Michael

If you are looking to run on a non-Windows platform and upgrading is not an option, you might be able to purchase a single user base PxPlus license to install and run independently of their Infor application.  You can then have the application INVOKE that version of PxPlus to parse the JSON.  You could place the JSON into a temporary file, invoke the newer version of PxPlus to parse the data and return the values. 

Depending on what you need to do, you might be able to do additional processing in this new version however it would not be able to access any protected INFOR data or programs. 

Basically, you would just be using this newer version of PxPlus much the same as if you wrote a program/interface in C, C++, Java or any other programming environment and invoked it.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com