Link to home
Start Free TrialLog in
Avatar of Mike Assad
Mike AssadFlag for United States of America

asked on

Importing a JSON response to MySQL in Laravel

I am using the API of a program to get data through Laravel's HTTP function. The request comes back in JSON format like this:

{
  "response": {
    "method": "12345",
    "result": {
      "calls": {
        "total_pages": "1",
        "total_items": "6",
        "call": [
          {
            "uniquevalue": "value",
            "key1": "value",
            "key2": "value",
            "key3": "value"
          },
          {
            "uniquevalue ": "value",
            "key1": "value",
            "key2": "value",
            "key3": "value"
          },
          {
            "uniquevalue ": "value",
            "key1": "value",
            "key2": "value",
            "key3": "value"
          }
        ],
        "items_per_page": "999",
        "page_number": "1"
      }
    }
  }
}

Open in new window

I want to take the data bolded above (each row under (response -> result-> calls -> call) and import them to a MySQL database. Normally, I would do this by doing a foreach loop, which may not be the right way. But in this case, I don't know how to do even that because I don't know how to access the nested json rows.
In summary, how can I get each of the "call" rows above into a database? Any advice is appreciated. Thank you.
Avatar of HainKurt
HainKurt
Flag of Canada image

you want this in JS/jQuery or php?
Avatar of Mike Assad

ASKER

I want it in php.
SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial