Page 1 of 1

Compound JSON Extraction

Posted: Tue Apr 16, 2024 9:35 pm
by PB_Newbie
I am querying an API that returns a large JSON string of the format:

Code: Select all

{"data":
  {
    "element1": number,
    "element2": number,
    ...
    "rows":
    [
      {
        "a": value,
        "b": value,
        ...
      },
      {
        "c": value,
        "d": value,
        ...
      },
      ...
    ],
    "elementN": number
  }
  "something": value
}
I'm having just a heck of a time trying to extract just the Array of Maps in jsonString -> data -> rows. I have defined a Structure with the fields and types

Code: Select all

Structure MyData
  field1.l
  field2.l
  ...
  fieldX.s
  fieldY.s
EndStructure
NewArray MyArray.MyData()
How can I extract the Array of Maps in rows into MyArray? I also care about a few of the other values, so I don't want to lose them.

Thanks!

Re: Compound JSON Extraction

Posted: Tue Apr 16, 2024 9:57 pm
by infratec
Look at

Code: Select all

ExtractJSONStructure()
https://www.purebasic.com/documentation ... cture.html

But your structure needs to fit the JSON$