DATA-GEN object 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/
Post Reply
Alvan
Posts: 1
Joined: Tue Aug 30, 2022 3:16 pm

DATA-GEN object name

Post by Alvan »

This is the JSON format that I've been told to use. Property1,2,3 would be set at 'run time'. That is to say those object names are variable and there will be a variable number of those objects. Is it possible to set up a data structure for DATA-GEN to create this JSON? I can generate the JSON other ways, but I was hoping to be able to use DATA-GEN.

Code: Select all

{
“SomeStuff”: “string”,  
“MoreStuff”: “string”,
"SomeInformation": {
    "Property1": {
      "Value1": "string",
      "Value2": "string"
    },
    "Property2": {
      "Value1": "string",
      "Value2": "string"
    },
    "Property3": {
      "Value1": "string",
      "Value2": "string"
    }
  },
}
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-GEN object name

Post by Scott Klement »

It might be more elegant (easier?) to do this using YAJL's subprocedure calls.

If you wanted to do it with data-gen, you'd need to code a data structure with many optional subfields. Each subfield would be conditioned with the "countprefix" and "nameprefix" options. You would set the count prefix variable for each element to 0 to indicate that you did not want to output the optional element, or to 1 to output it. Set the name prefix variable to the name of the element you wanted to output.

So that would be possible, but perhaps ugly?

Personally, when a JSON document is more dynamic like this one, I prefer to just call the subprocedures. They feel much more elegant to me for dynamic (calculated-on-the-fly) data.
Post Reply