JSON is a text notation of a javascript object that is a hierarchical data
structure where the hierarchy is made by arrays and objects that contains
data in nodes – sounds easy if you understand it ;-)

YAJL and SQL is two different ways to process JSON where YAJL emulates the
methods in javascript and SQL tries to read JSON what it is not basically
build for and you have to choose one or the other.

The YAJL vs. SQL discussion is not for this tread since it is a matter of
what code centric and method one wish to follow and what type of developer
one is e.g. back-end, front-end or full stack.

When you write about data structures (defined in the RPGLE program) it has
nothing to do with processing JSON since it is just a collection of
internal fields in the program you may or may not PUT data from JSON into
using either YAJL or SQL. Unlike XML-INTO there is no automatic mapping of
data between the JSON and the data structure.

JSON consist of data in a node, collection of nodes in an object { } and
collections of similar objects { } in an array [ ]

A node in JSON may be one of two things – simple data types (string,
number, boolean etc.) , complex data type (array, object) and the syntax is

“nodename” : “data”

In simple JSON you may mindmap the structure to a file/table where

file/table = JSON file - (yourjson.json)

records/rows = JSON array - [ … ]

record/row = JSON object - { … }

field/column = JSON node - “nodename” : “data”

The above is exactly what you see in the above JSON you have posted but
because JSON has a complex node types (array/object) we can take the simple
JSON you have posted and embed it in more complex JSON.


“success” : true,

“message” : “data is OK”,

“yourdata” : [ … your JSON file … ]


The difference is that before your JSON file existed in the JSON root, now
it exists as a JSON node (yourdata) as a complex data type within a JSON
object and therefore you have to qualify the JSON node name before you can
read the data in your JSON file.

So normally your JSON with a success property would look like the following


“success” : true,

“yourdata” : [
{"name":"George Washington", "life":"1732-1799", "term":"1789-04-30
to 1797-03-04", "party":"No Party"},
{"name":"John Adams", "life":"1735-1826", "term":"1797-03-04 to
1801-03-04", "party":"Federalist"}



I hope this clarifies JSON a little.

On Thu, Sep 7, 2017 at 4:30 AM, Booth Martin <booth@xxxxxxxxxxxx> wrote:

This confuses me.

I am using the example in JSONREAD2,rpgle.txt, with the list_t fields
changed and QSYSPRT deleted. The qualified data structure Result has a
subfield called "success." It is not in the JSON qualified template data
structure named list_t. I do not see a "success" node? But then, I am not
completely sure what a node is. If I understand correctly the node is
blank and the elements are name, life, term, and party?

The JSON file looks like this:

{"name":"George Washington", "life":"1732-1799", "term":"1789-04-30
to 1797-03-04", "party":"No Party"},
{"name":"John Adams", "life":"1735-1826", "term":"1797-03-04 to
1801-03-04", "party":"Federalist"},
{"name":"Thomas Jefferson", "life":"1743-1826", "term":"1801-03-04
to 1809-03-04", "party":"Democratic-Republican"},
{"name":"James Madison", "life":"1751-1836", "term":"1809-03-04 to
1817-03-04", "party":"Democratic-Republican"},
{"name":"James Monroe", "life":"1758-1831", "term":"1817-03-04 to
1825-03-04", "party":"Democratic-Republican"},
{"name":"John Quincy Adams", "life":"1767-1848", "term":"1825-03-04
to 1829-03-04", "party":"Democratic-Republican"},
{"name":"Andrew Jackson", "life":"1767-1845", "term":"1829-03-04 to
1837-03-04", "party":"Democratic"},
{"name":"Martin Van Buren", "life":"1782-1862", "term":"1837-03-04
to 1841-04-04", "party":"Democratic"},
{"name":"William Henry Harrison", "life":"1773-1841",
"term":"1841-03-04 to 1841-04-04", "party":"Whig"},
{"name":"John Tyler", "life":"1790-1862", "term":"1841-04-04 to
1845-03-04", "party":"Whig"},
{"name":"James K. Polk", "life":"1795-1849", "term":"1845-03-04 to
1849-03-04", "party":"Democratic"},
{"name":"Zachary Taylor", "life":"1784-1850", "term":"1849-03-04 to
1850-07-09", "party":"Whig"},
{"name":"Millard Fillmore", "life":"1800-1874", "term":"1850-07-09
to 1853-03-04", "party":"Whig"},
{"name":"Franklin Pierce", "life":"1804-1869", "term":"1853-03-04 to
1857-03-04", "party":"Democratic"},
{"name":"James Buchanan", "life":"1791-1868", "term":"1857-03-04 to
1861-03-04", "party":"Democratic"},
{"name":"Abraham Lincoln", "life":"1809-1865", "term":"1861-03-04 to
1865-04-15", "party":"Republican"},
{"name":"Andrew Johnson", "life":"1808-1875", "term":"1865-04-15 to
1869-03-04", "party":"Democratic"},
{"name":"Ulysses S. Grant", "life":"1822-1885", "term":"1869-03-04
to 1877-03-04", "party":"Republican"},
{"name":"Rutherford B. Hayes", "life":"1822-1893",
"term":"1877-03-04 to 1881-03-04", "party":"Republican"},
{"name":"James A. Garfield", "life":"1831-1881", "term":"1881-03-04
to 1881-09-19", "party":"Republican"},
{"name":"Chester A. Arthur", "life":"1829-1886", "term":"1881-09-19
to 1885-03-04", "party":"Republican"},
{"name":"Grover Cleveland", "life":"1837-1908", "term":"1885-03-04
to 1889-03-04", "party":"Democratic"},
{"name":"Benjamin Harrison", "life":"1833-1901", "term":"1889-03-04
to 1893-03-04", "party":"Republican"},
{"name":"Grover Cleveland", "life":"1837-1908", "term":"1893-03-04
to 1897-03-04", "party":"Democratic"},
{"name":"William McKinley", "life":"1843-1901", "term":"1897-03-04
to 1901-09-14", "party":"Republican"},
{"name":"Theodore Roosevelt", "life":"1858-1919", "term":"1901-09-14
to 1909-03-04", "party":"Republican"},
{"name":"William Howard Taft", "life":"1857-1930",
"term":"1909-03-04 to 1913-03-04", "party":"Republican"},
{"name":"Woodrow Wilson", "life":"1856-1924", "term":"1913-03-04 to
1921-03-04", "party":"Democratic"},
{"name":"Warren G. Harding", "life":"1865-1923", "term":"1921-03-04
to 1923-08-02", "party":"Republican"},
{"name":"Calvin Coolidge", "life":"1872-1933", "term":"1923-08-02 to
1929-03-04", "party":"Republican"},
{"name":"Herbert Hoover", "life":"1874-1964", "term":"1929-03-04 to
1933-03-04", "party":"Republican"},
{"name":"Franklin D. Roosevelt", "life":"1882-1945",
"term":"1933-03-04 to 1945-04-12", "party":"Democratic"},
{"name":"Harry S. Truman", "life":"1884-1972", "term":"1945-04-12 to
1953-01-20", "party":"Democratic"},
{"name":"Dwight D. Eisenhower", "life":"1890-1969",
"term":"1953-01-20 to 1961-01-20", "party":"Republican"},
{"name":"John F. Kennedy", "life":"1917-1963", "term":"1961-01-20 to
1963-11-22", "party":"Democratic"},
{"name":"Lyndon B. Johnson", "life":"1908-1973", "term":"1963-11-22
to 1969-01-20", "party":"Democratic"},
{"name":"Richard Nixon", "life":"1913-1994", "term":"1969-01-20 to
1974-08-09", "party":"Republican"},
{"name":"Gerald Ford", "life":"1913-2006", "term":"1974-08-09 to
1977-01-20", "party":"Republican"},
{"name":"Jimmy Carter", "life":"1924-2100", "term":"1977-01-20 to
1981-01-20", "party":"Democratic"},
{"name":"Ronald Reagan", "life":"1911-2004", "term":"1981-01-20 to
1989-01-20", "party":"Republican"},
{"name":"George H. W. Bush", "life":"1924-2100", "term":"1989-01-20
to 1993-01-20", "party":"Republican"},
{"name":"Bill Clinton", "life":"1946-2100", "term":"1993-01-20 to
2001-01-20", "party":"Democratic"},
{"name":"George W. Bush", "life":"1946-2100", "term":"2001-01-20 to
2009-01-20", "party":"Republican"},
{"name":"Barack Obama", "life":"1961-2100", "term":"2009-01-20 to
2017-01-20", "party":"Democratic"}

On 9/5/2017 11:29 PM, Scott Klement wrote:


I don't understand. You say you're getting a lexical error -- but then
you also say that yajl_object_find() is failing to find the "success" node.

1) If you're getting a lexical error, then docNode should be *null, and
errMsg = 'The Lexical Error Message'. Your code doesn't actually call
yajl_object_find when errMsg isn't blank.

2) Do you understand that the 2nd parameter in yajl_object_find() is the
name of the JSON element you are trying to retrieve? You are asking for an
element named 'success' inside your document. So your document would look
like this:

"success": true,
.. other stuff ...

Are you sure it has a "success" element in it? The examples you posted
earlier did not.

You didn't answer my questions about the SQL LOB and SUBSTR, either.


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: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related

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

This thread ...


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

This mailing list archive is Copyright 1997-2020 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].