"node" is just a generic word for some element in the document. It is very unspecific. No, none of the nodes you provided here are empty. Some contain other nodes, and some contain data. When the code says "node", just think of it as "pointer to where a particular json thing is in memory".

Once you have that pointer, you can get something from the node, whether it's child nodes (i.e. other nodes within that node) or data (such as numbers or strings).

In JSON square brackets [] mean an "array" and curly braces {} mean a "data structure" (or "object" in JSON terminology.)

Your document is laid out like this:

{"name":"string", "life":"string", "term":"string", "party":"string"}
.. records repeat ..

So what you have is an array of data structures. Each data structure has fields in its. Maybe it'd be easier for you to think of the array as a "file", and each object as a "record" in that file.

However you look at it, there is no field in the file named "success". There was in my example that you copied it from, but there isn't a field named "success" in your example. So asking YAJL for a field named success will return *NULL... make sense?

What you want to do is use YAJL_ARRAY_LOOP to loop through the contents of the array. It will return the array index and a node pointer for each array element. Then you can use YAJL_object_find() to find the node pointer within that array for a given field, and YAJL_get_string() to retrieve a string from the node.

I put together an example, using your data, that reads everything into an RPG data structure array, and then loops through that RPG array and prints it out.

H dftactgrp(*no) bnddir('YAJL')


/copy YAJL_H

D presidents ds qualified
D dim(100)
D name 25a varying
D life 9a varying
D term 24a varying
D party 21a varying

D prt ds likeds(presidents)

D errMsg s 500a varying inz('')
D docNode s like(yajl_val)
D rec s like(yajl_val)
D node s like(yajl_val)
D i s 10i 0
D count s 10i 0


docNode = YAJL_stmf_load_tree( '/path/to/file': errMsg );
if errMsg <> '';
// whine about it and exit

i = 0;
count = 0;

dow YAJL_ARRAY_LOOP(docNode: i: rec);

node = YAJL_object_find(rec: 'name');
presidents(i).name = YAJL_get_string(node);

node = YAJL_object_find(rec: 'life');
presidents(i).life = YAJL_get_string(node);

node = YAJL_object_find(rec: 'term');
presidents(i).term = YAJL_get_string(node);

node = YAJL_object_find(rec: 'party');
presidents(i).party = YAJL_get_string(node);

count = count + 1;



// just to provide an example of doing something with the
// data, make a quick printout (I didn't bother making
// headers, et al)

for i = 1 to count;
eval-corr prt = presidents(i);
except PRINTME;

*inlr = *on;

O 25
O 36
O prt.term 62
O 85

I tried this program on your data, and it seemed to work perfectly fine. I did not get any lexical errors, etc. But then you have consistently refused to tell me more about the lexical errors, and have avoided the subject since it was brought up.


On 9/6/2017 9:30 PM, Booth Martin 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 thread ...


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

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