× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Mon, Mar 19, 2018 at 6:36 PM, Henrik Rützou <hr@xxxxxxxxxxxx> wrote:

Mark

just to clarify - JSON is a text notation of a javascript object - so like
at javascript object
it may start with either an object "{" litteral or an array "[" litteral so
this is perfectly valid
JSON:

[ { "propertyA" : "abc", "propertyB" : "def" }, { "propertyA" : "ghi",
"propertyB" : "jkl" } ]


That's right, I said the outside construct has to be an object, but it can
be a list as well.


another thing is that JSON is not easy unless your program language and
thereby your
editor (like VSCODE) supports the format - if you just use notepad you end
up in a
comma hell.


When I said JSON was simple, I was comparing it to XML, since simple is a
relative thing rather than an absolute.


The easiest way to create JSON are actually in javascript where you do no
create a
string you add to but creates an object that you are able to manipulate as
you like e.g.
you can create the whole body first and then at sections (e.g. rows) as you
go an when
finished create the string in one instruction (JSON.stringify())


Yes, but we aren't talking about javascript are we. It's pretty simple to
generate (and consume) JSON from PHP as well using json_encode (and
json_decode). but we aren't talking about PHP either. What I was saying was
that DATA_INTO is a great start, and it would be even better if we had a
DATA_FROM which just reversed the process as Barbara mentioned. Given PHP's
json_encode/json_decode functions, it should be doable. Certainly for JSON,
maybe even for XML.


For other languages (including RPG) there is YAJL that simulates the
Javascript Object
in some extent.

In regards to creating XML, Jon Paris wrote a section in the Modernization
Manual
describing severel methods and plugins to do the job (amoung those my own)
so it
is just a matter of doing like anybody alese - look in the Open Source
community where
you often find a solution that even includes procedures for sending or
saving your generated
documents and also does the rigtht encoding of special characters.

Or last but not at least, go for SQL that for some seems to be the problem
for all lacking
wishes in RPG.


Yes there are tools that exist for generating and consuming JSON in RPG.
But a feature can always be better when it is built into the language
because the compiler has access to data that the language does not.


On Mon, Mar 19, 2018 at 8:46 PM, Mark Murphy <jmarkmurphy@xxxxxxxxx>
wrote:

I don't know about that. XML-INTO handles missing or extra elements, and
name spaces with options and prefixes. DATA/XML-FROM could work
similarly.
For example:

Options could define an attributePrefix=atr_ then

dcl-ds accounts;
dcl-ds account dim(99);
Id char(6);
name char(30);
end-ds;
end-ds;

Should result in:

<accounts>
<account>
<id>xxxxxx</id>
<name>name stuff</name>
</accoun>
<account>
<id>yyyyyy</id>
<name>name stuff</name>
</accoun>
....
</accounts>

and

dcl-ds accounts;
dcl-ds account dim(99);
atr_Id char(6);
name char(30);
end-ds;
end-ds;

Should result in:

<accounts>
<account "id=xxxxxx">
<name>name stuff</name>
</accoun>
<account "id=yyyyyy">
<name>name stuff</name>
</accoun>
....
</accounts>

Blank character fields could result in a missing element. Likewise
numeric
elements with a value of 0 could result in a missing element. Or an
option
could control that. A count field with a prefix option could be used to
specify the number of elements to produce for multiple elements.

I would expect generation of JSON to be even easier as there are only a
few
ways to create valid JSON as opposed to XML. JSON has no name-space to
deal
with, and no schemas either. There is no need to differentiate between
attributes and values, JSON has only values. JSON always starts with an
object which is a collection of name:value pairs. A name is always a
string. A value can be a string, a number, a list, or an object. A list
is
a collection of values. A string is surrounded by double quotes, a number
isn't. An object is surrounded by curly braces, and a list is surrounded
by
square brackets. That is the whole spec.

On Mon, Mar 19, 2018 at 3:15 PM, Jon Paris <jon.paris@xxxxxxxxxxxxxx>
wrote:

Easier said than done Mark.

COBOL has an XML generation capability built in - but most of the time
you
still need to transform it before it can be used.

For example - given a DS like this:

dcl-ds accounts;
dcl-ds account dim(99);
Id char(6);
name char(30);
end-ds;
end-ds;

Should that result in:

<accounts>
<account>
<id>xxxxxx</id>
<name>name stuff</name>
</accoun>
<account>
<id>yyyyyy</id>
<name>name stuff</name>
</accoun>
....
</accounts>

Or

<accounts>
<account "id=xxxxxx">
<name>name stuff</name>
</accoun>
<account "id=yyyyyy">
<name>name stuff</name>
</accoun>
....
</accounts>


And that is just a trivial example. I suspect for JSON it would be
even
worse as the rules are not as strict as for XML and people do really
strange things.


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On Mar 19, 2018, at 9:22 AM, Mark Murphy <jmarkmurphy@xxxxxxxxx>
wrote:

Great, now all we need to complete that picture is a DATA-FROM (and
maybe
even an XML-FROM) to make it simple to produce JSON or whatever data
interchange format from a data structure.

On Fri, Mar 16, 2018 at 4:55 PM, Barbara Morris <bmorris@xxxxxxxxxx>
wrote:

On 2018-03-16 11:35 AM, Barbara Morris wrote:

The latest enhancement for RPG is available for 7.2 and 7.3: The
DATA-INTO opcode. It's like XML-INTO, but for any structured
language,
such
as JSON. The big difference between DATA-INTO and XML-INTO is that
you
have
to supply the parser for the structured language.


Here's a article by Jon Paris about DATA-INTO:
http://ibmsystemsmag.com/ibmi/developer/rpg/rpg-data-into/


--
Barbara

--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our
affiliate
link: http://amzn.to/2dEadiD

--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our
affiliate
link: http://amzn.to/2dEadiD

--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD




--
Regards,
Henrik Rützou

http://powerEXT.org <http://powerext.org/>
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.