DATA-INTO. missing nodes name

Discussions relating to the ScottKlement.com port of the open source YAJL JSON Reader/Generator. This includes the YAJL tool as well as the YAJLR4, YAJLGEN, YAJLINTO and YAJLDTAGEN add-ons from ScottKlement.com. http://www.scottklement.com/yajl/
pargent70
Posts: 5
Joined: Tue Aug 30, 2022 7:54 am

DATA-INTO. missing nodes name

Post by pargent70 »

I have a json like this, from comeback to external api calling

{
"Carriers":
{"Carrier1":[
{"CarrierID":"3103",
"CarrierService":"Standard"
],
"Carrier2":[
{"CarrierID":"1392",
"CarrierService":"Standard"
],
"Carrier3":[
{"CarrierID":"3678",
"CarrierService":"Standard"
],
"Carrier4":[
{"CarrierID":"384",
"CarrierService":"Standard"
],
"Carrier5":[
{"CarrierID":"2098",
"CarrierService":"Standard"
{"CarrierID":"2099",
"CarrierService":"Standard"
]
},
"ValidationErrors":"text message"
}

I don't know the names of the nodes related to the Carriers ( Carrier1, Carrier2, etc),
until I get the json.
with "path" parameter I overcome the problem about the missing json root name,
but then, how can I define the DS to be used in the DATA-INTO?
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-INTO. missing nodes name

Post by Scott Klement »

Unfortunately, you really can't use variable names with DATA-INTO, because RPG needs to know the names at compile-time.

If there's a limited number of them, you could hard-code all of them into your data structure, and make them all optional, then only the appropriate ones would be filled in.

However, if you want it to be truly dynamic, you shouldn't use DATA-INTO. Instead, use the YAJL subprocedures, they will allow you to make it completely dynamic.

If you are able to influence the design of this JSON document, I would submit that this isn't a very good design. The field names should identify WHAT something is, they should not be used for data. Using the field names to identify a given carrier violates that design rule, and makes it more difficult to interpret the document -- it is not a good design. But, if you aren't involved in the design process, and must simply use a document that is already in place, then go with the YAJL subprocedures.
pargent70
Posts: 5
Joined: Tue Aug 30, 2022 7:54 am

Re: DATA-INTO. missing nodes name

Post by pargent70 »

Thanks Scott.

right now I'm not able to ask for a change format.

with Php I already did a script to work with this json,
maybe I will do something to store the nodes name on a table
and then use this to create something to reuse on rpgle
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-INTO. missing nodes name

Post by Scott Klement »

Hmm... not sure how it helps to have the node's name in a table. Just read it from the JSON document... can't do that with DATA-INTO, but you can with the YAJL subprocedures.
pargent70
Posts: 5
Joined: Tue Aug 30, 2022 7:54 am

Re: DATA-INTO. missing nodes name

Post by pargent70 »

The idea could be to Read this table and work with path parameter for each node
So I can use data-into for little portion of json

I have to try, tomorrow

Thanks again
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-INTO. missing nodes name

Post by Scott Klement »

So you're going to use a separate call to data-into for every node you need? And then someone is going to populate the table with the name of those nodes?

Seems like a lot of extra work and a very inneficient program. What would be the advantage of doing it this way?
pargent70
Posts: 5
Joined: Tue Aug 30, 2022 7:54 am

Re: DATA-INTO. missing nodes name

Post by pargent70 »

I already tried with YAJL subprocedures with no result.
I will try again, maybe I did mistakes...

You right, my Solution is not efficient,
I reserve it as last chance
peder udesen
Posts: 15
Joined: Thu Jul 29, 2021 8:00 am

Re: DATA-INTO. missing nodes name

Post by peder udesen »

Perhaps you can do it by coding a handler for Rational Open Access
using "Handling input data using name-value information"

Check it here:
https://www.ibm.com/docs/en/i/7.4?topic ... input-data
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-INTO. missing nodes name

Post by Scott Klement »

peder udesen wrote: Wed Aug 31, 2022 8:40 am Perhaps you can do it by coding a handler for Rational Open Access
using "Handling input data using name-value information"
I'm struggling to see how that helps, unless the individual "carrier" names correspond to the names of externally defined fields? Then it might help because the OA handler would hand you the field names... but they'd still have to be known when you compile the calling RPG program, because that's just how external definitions work in RPG, they're compiled in.

Within the OA handler code, you'd still have to call the YAJL procedures (or a similar set of JSON routines) so I don't really see how this saves you anything?
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-INTO. missing nodes name

Post by Scott Klement »

Looking more closely at your example document -- it's not valid JSON. There are many places where you try to put an object key name inside an array (rather than an object.) And places where you start an array and an object, but then close only the array and not the object, leading to a lot of errors within the document. No JSON parser can read the document you posted.

I'm assuming that you typed that document off the top of your head (rather than copy/paste) and what you really meant was a document like this:

Code: Select all

{
  "Carriers": {
    "Carrier1": {
      "CarrierID": "3103",
      "CarrierService": "Standard"
    },
    "Carrier2": {
      "CarrierID": "1392",
      "CarrierService": "Standard"
    },
    "Carrier3": {
      "CarrierID": "3678",
      "CarrierService": "Standard"
    },
    "Carrier4": {
      "CarrierID": "384",
      "CarrierService": "Standard"
    },
    "Carrier5": {
      "CarrierID": "2098",
      "CarrierService": "Standard"
    },
    "Carrier6": {
      "CarrierID": "2099",
      "CarrierService": "Standard"
    }
  },
  "ValidationErrors": "text message"
}
Post Reply