1. Sivaprakash BKR
  2. PowerBuilder
  3. Monday, 12 August 2019 15:40 PM UTC

Hello,

Using PB 2017 R3,   

Trying to import a JSON file created by a third party, into a datawindow.   The siva2.rar (attached) opens well in Notepad++, with proper plugins.   Notepad ++ displays the data perfectly.

Now, when I try to import with either

ll_RowCount = dw_1.ImportJsonByKey(ls_Json, ls_error)            Or
ll_rowcount = dw_1.ImportJsON(ls_json, ls_error)

Messagebox('Rows', ll_rowcount)
I get error -5 - Invalid JSON Format

Looks like the format is not as expected by ImportJSON* functions. 

Tried reading the JSON file using JSONParser and calling a recursive function to read all the values.  I could read all the values, but struck when to add a row to a datawindow and fill all required values.   Could not arrive a logic to fill all columns by inserting a row (at what point).  

Any help in transferring this json data into datawindow, if possible with codesnippet, will be very much helpful.

Happiness Always
BKR Sivaprakash

 

Attachments (1)
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Wednesday, 14 August 2019 04:48 AM UTC
  2. PowerBuilder
  3. # 1

Thanks Kevin,

That's what I was thinking, to into a treeview datawindow, as Notepad++ also displays the things in a treeview manner.  I'll try before connecting you.

By the way, https://json-csv.com/ does a beautiful work of converting such json files to CSV files.   My thinking is that if that could be done, there should be a way to convert into a tabular / grid datawindow also.  Just thinking...

Happiness Always
BKR Sivaprakash

 

Comment
There are no comments made yet.
Kevin Ridley Accepted Answer Pending Moderation
  1. Monday, 12 August 2019 18:08 PM UTC
  2. PowerBuilder
  3. # 2

The problem is the JSON is not "flat".  In order for the ImportJSON to work, the data needs to be flat.  You've got the b2b array, but that contains a inv array which contains itms array.  You are going to have to pull them out separately and populate your DW.  This is a great example of why we need the treeview dw to be expanded to be able to import this complex json.  It's all do-able, and I would still put it in a Treeview dw, but you're going to have to populate it manually.  You can contact me via LinkedIn if you need to have this done outside your organization.  There's also a bug you'll need to watch out for when getting null values from JSON.  I've logged the bug (2613) and hoping that they will fix it soon.

Kevin

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.