What is the best way to 'build' complex JSON file from values in DB?

Hi All,

I’m looking into using a 3rd party service that provides specific AI business logic on a bunch of data. Naturally its all done through APIs. So far I’ve tested it out with sample data and the API connector in Server Connect and its all working fine. Great work Wappler!

Next though i need to look into how i will build the POST JSON file from data that will eventually all come from my DB. I know that the SC files output as JSON, as as long as the naming convention lines up, you could easily just use a SC file as the JSON to post with.

What happens though when its quite a complex JSON file with lots of nested layers of data? Is it just a matter of carefully crafting your server connect steps, using repeats as necessary to get the right structure?

Here’s an example of what i would need to create/build all from data in my DB. Are there other tools in Wappler to help create this JSON file, or just the multiple DB query steps in server connect?

  "id": "f515b917-acec-4bf0-939d-a0051f447xyz",
  "solver": "SHIFT",
  "demand": [
    {
        "shift": {
          "date": "2020-09-14",
          "index": 0
        },
        "skill": "Service",
        "prefDemand": 21        
      }
  ],
  "statutes": [
    {
      "name": "FIX",
      "minShiftLength": 3,
      "maxShiftLength": 11
    }
  ],
  "employees": [
    {
      "name": "E0",
      "statute": "FIX",
      "skill": [
        {
          "name": "Restaurant"
        }
      ],
      "hourlyPay": 11.0,
      "preferences": [
        {
          "start": "2020-09-12T08:00:00",
          "end": "2020-09-12T12:00:00"
        },
        {
          "start": "2020-09-12T14:00:00",
          "end": "2020-09-12T18:00:00"
        }
      ],
      "preferredShiftLength": 5.0,
      "preferredHoursPerWeek": 38.0,
      "efficiency": 1.0,
      "hoursWorkedThisMonth": 0,
      "lastRestDate": "2020-09-09"
    }
  ],
  "assignments": [],
  "solve_duration": 0
}
1 Like

What did you find out on this?

I would use RunJS (on NodeJS projects)

@jellederijke managed to do it without RunJS:
image
image

1 Like