Page 1 of 1

DATA-GEN object name

Posted: Tue Aug 30, 2022 3:59 pm
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"
    }
  },
}

Re: DATA-GEN object name

Posted: Tue Aug 30, 2022 4:08 pm
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.