JSON Parser in Omnis Code / Studio 4.3.2.1 Non-Unicode
Hi Rudolf,
Understood. I do have XML Parsers for more complex data sets for Medical
Lab Results that break the response down into blocks and then pull the data
from them to build lists.
But so far, I have not had any integrations that use JASON for more than one
set of data points.
I do find JASON a little more challenging to deal with because character
data is surrounded by double quotes and numbers are not. Also, the fact
that each data element in a set ends with a comma accept the last one is
something I always seem to forget about.
I have never gotten to elaborate either. Nothing over generalized. Just
get the smallest fastest chunk of code I can think of to get the job done.
*********************************************************************
Michael Mantkowski
ClienTrax Software
1-614-875-2245
*********************************************************************
—–Original Message—–
From: omnisdev-en [mailto:omnisdev-en-bounces@lists.omnis-dev.com] On Behalf
Of Rudolf Bargholz
Sent: Monday, October 30, 2017 10:07 AM
To: OmnisDev List – English <omnisdev-en@lists.omnis-dev.com>
Subject: AW: JSON Parser in Omnis Code / Studio 4.3.2.1 Non-Unicode
Hi Mike,
The structures I need to process can be a little more complex, so the your
code below would not really fit my needs.
Invested two hours, and was able to hash together a recursive JSON parser
that takes apart a JSON, fills the objects into Studio Row variables, where
a string is a column name, the value a column value. A column value of type
array maps to an Omnis list, so the value of the column is then a list with
one column of type row. The code probably does not handle many edge cases,
and error handling is non-existent at the moment , but is able to parse the
following into a row with two columns ReturnCode of type Character and
CostCenterItems of type List where the list variable has one column of type
row, and each row has the columns CONTROLLINGAREA, COSTCENTER, …,
LastChangedDate, with each row column value corresponding to the value of
the JSON object.
Here a link to a demo library, in case you are interested:
www.sugarsync.com/pf/D6405663_06260637_9679555
{
“ReturnCode”: “1 “,
“CostCenterItems”: [
{
“CONTROLLINGAREA”: 1000,
“COSTCENTER”: 1000100000,
“VALID_FROM”: “2017-01-01”,
“VALID_TO”: “9999-12-31”,
“PERSON_IN_CHARGE”: “Rudolf Bargholz”,
“DEPARTMENT”: “”,
“COSTCENTER_TYPE”: “W”,
“COSTCTR_HIER_GRP”: 100010000,
“COMP_CODE”: 1000,
“PROFIT_CTR”: “0000004000”,
“LOCK_IND_ACTUAL_PRIMARY_COSTS”: “”,
“NAME”: “”,
“DESCRIPT”: “”,
“PERSON_IN_CHARGE_USER”: “”,
“Active”: true,
“LastChangedDate”: “2017-08-04T00:00:01Z”
},
{
“CONTROLLINGAREA”: 1000,
“COSTCENTER”: 1000200000,
“VALID_FROM”: “2017-01-01”,
“VALID_TO”: “9999-12-31”,
“PERSON_IN_CHARGE”: “Sandra Bargholz”,
“DEPARTMENT”: “”,
“COSTCENTER_TYPE”: “W”,
“COSTCTR_HIER_GRP”: 100020000,
“COMP_CODE”: 1000,
“PROFIT_CTR”: “0000004000”,
“LOCK_IND_ACTUAL_PRIMARY_COSTS”: “”,
“NAME”: “”,
“DESCRIPT”: “”,
“PERSON_IN_CHARGE_USER”: “”,
“Active”: true,
“LastChangedDate”: “2017-08-04T00:00:01Z”
}
]
}
As a starting point this handles what I want to do.
Thanks for your help.
Regards
Rudolf Bargholz
—–Ursprüngliche Nachricht—–
Von: omnisdev-en [mailto:omnisdev-en-bounces@lists.omnis-dev.com] Im Auftrag
von Michael Mantkowski
Gesendet: Montag, 30. Oktober 2017 12:32
An: ‘OmnisDev List – English’ <omnisdev-en@lists.omnis-dev.com>
Betreff: RE: JSON Parser in Omnis Code / Studio 4.3.2.1 Non-Unicode
Hi Rudolf,
Not sure what your end goal is… But I use the following to pick data out
of JASON text. Requires pre-knowledge of what you are looking for.
lvResponseText is the data received back from a POST or GET call to a Web
Service.
Do method ——getJASONtag (‘”caseID”‘,lvResponseText) Returns pvCaseNo
; Get JASON tag value
Calculate lvText as mid(pvText,pos(pvTag,pvText),len(pvText))
Calculate lvText as mid(lvText,1,pos(‘}’,lvText)) Calculate lvText as
mid(lvText,pos(‘:’,lvText)+1,len(lvText))
If pos(‘,’,lvText)>0
Calculate lvText as mid(lvText,1,pos(‘,’,lvText)-1) Else
Calculate lvText as mid(lvText,1,pos(‘}’,lvText)-1) End If Calculate
lvText as replaceall(lvText,kDq,”) Quit method lvText
*********************************************************************
Michael Mantkowski
ClienTrax Software
1-614-875-2245
*********************************************************************
—–Original Message—–
From: omnisdev-en [mailto:omnisdev-en-bounces@lists.omnis-dev.com] On Behalf
Of Rudolf Bargholz
Sent: Monday, October 30, 2017 5:55 AM
To: ‘OmnisDev List – English’ <omnisdev-en@lists.omnis-dev.com>
Subject: JSON Parser in Omnis Code / Studio 4.3.2.1 Non-Unicode
Hi,
Has anyone written a simple Omnis JSON parser in Omnis code that they might
be willing to share? I just need to take apart some JSON, performance is not
really an issue, an Omnis Upgrade to a newer version of Omnis is not
possible, so it would have to be in native Omnis Studio code.
I have an idea how to do this, but if I someone has done this already, and
is willing to share their code, it would save me some time.
Regards
Rudolf
_____________________________________________________________
Manage your list subscriptions at lists.omnis-dev.com
_____________________________________________________________
Manage your list subscriptions at lists.omnis-dev.com
_____________________________________________________________
Manage your list subscriptions at lists.omnis-dev.com
_____________________________________________________________
Manage your list subscriptions at lists.omnis-dev.com