-3

I've a raw JSON data in string format(collected from API).

"0": {
"name": "Powerball",
"plays": [
  {
    "name": "Powerball",
    "active": null,
    "draws": [
      {
        "date": "08\/22\/2022",
        "nextDrawDate": "08\/24\/2022",
        "nextDrawJackpot": 100000000,
        "numbers": [
          {
            "value": "12",
            "order": 1,
            "specialBall": null
          },
          {
            "value": "27",
            "order": 2,
            "specialBall": null
          },
          {
            "value": "34",
            "order": 3,
            "specialBall": null
          },
          {
            "value": "55",
            "order": 4,
            "specialBall": null
          },
          {
            "value": "67",
            "order": 5,
            "specialBall": null
          },
          {
            "value": "09",
            "order": 6,
            "specialBall": {
              "name": "Powerball"
            }
          },
          {
            "value": "2",
            "order": 7,
            "specialBall": {
              "name": "Power Play"
            }
          }
        ],
        "prizes": [
          
        ],
        "extraFields": [
          
        ]
      }
    ]
  }

now i've to get this data and do some logic which is alraedy done by POSTMAN.But,now i've try this out without POSTMAN,but can't call the API.So,i've to make a dummy API which'll just have to send the JSON data to my PHP(for example,getAPIData.php).I don't know how to do it?Any help would be appreciated

  • That's not valid JSON. It's also not clear what your question is. Are you trying to send some JSON to an API and it's not working or are you trying to build a PHP service to accept a JSON request body? – Phil Aug 24 '22 at 05:05
  • No,i just want to create a dummy api for testing...i need to get that JSON from that dummy API and make some process which is already done.So,for that i need to send that JSON to my PHP page(maybe using file_get_contents) but i don't know how to send string formatted JSON – sayantan poddar Aug 24 '22 at 05:13
  • `i need to send that JSON to my PHP page`...ok well first make it into valid JSON, and then read [Receive JSON POST with PHP](https://stackoverflow.com/questions/18866571/receive-json-post-with-php) to understand how to set up your PHP code to read the incoming data. Then you can use Postman (or any other relevant tool) to send test data to the PHP script. If you want to send data to that script from another different PHP script, you can use cURL or Guzzle for that. – ADyson Aug 24 '22 at 08:29

1 Answers1

2

This is all you need to do. Hope it helps

<?php

$api_url = 'your url here';

// Read JSON file
$json_data = file_get_contents($api_url);

// Decode JSON data into PHP array
$response_data = json_decode($json_data);

// All data exists in 'data' object
$user_data = $response_data->data;

// Print data if need to debug
//print_r($user_data);

// Traverse array and display user data
foreach ($user_data as $user) {
    echo "name: ".$user->employee_name;
    echo "<br />";
    echo "name: ".$user->employee_age;
    echo "<br /> <br />";
}

?>