Server API post, How do I create JSON input from a query (multiple records)

Hi everyone,

Here’s my scenario. I am issuing an API request to an AWS service and want to submit a list of questions and answers. Here is a sample JSON body.

{
“key”: “testkey”,
“faq”: [
{
“q”: “Question 1?”,
“a”: “Answer to Question 1.”,
“index”: 0
},
{
“q”: “Question 2?”,
“a”: “Answer to Question 2.”,
“index”: 1
}
],
“company”: “Test Company”
}

For the key and company fields I pass in $_POST variables. For q, a, and index I need to be able to query a “question” table that has q, a, and question_id as values. Query response is 1…n records per company.

How do I dynamically create this list of question, answers and index and pass this json data to a server side submit request / action? Thanks for the thoughts, help and suggestions.

Let me know if you need any additional details.

Community Page
Last updated: