0

I am currently struggeling to only display a certain part of a JSON object array in php.

My code looks like this:

    <?php 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '...correct-link-here...');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Token token=...api-key-here...',
    'Accept: application/vnd.api+json'
    ));

$output = curl_exec($ch);
$data = json_decode($output, true);

curl_close($ch);

?>

The result is something like this (short version below):

{
  "data": {
    "id": "awesome-conf",
    "type": "events",
    "attributes": {
      "banner-url": null,
      "currency": "USD",
      "description": "",
      "end-date": null,
      "live": false,
      "location": null,
      "logo-url": null,
      "private": false,
      "slug": null,
      "start-date": null,
      "title": null
    },
    "links": {
      "self": "https://api.tito.io/v2/an-account/awesome-conf"
    },
    "relationships": {
      "releases": {
        "links": {
          "related": "https://api.tito.io/v2/an-account/awesome-conf/releases"
        }
      }
    }
  }
}

I only want the id, logo-url, start-date and title to be displayed. Does somebody know how that could work? I couldn't find anything that worked on the internet for me.

Thank you very much! - Isabel

  • do you know how to create/edit/destroy a object? – madalinivascu Oct 02 '17 at 11:36
  • There is no thing like *"JSON object"* or *"JSON array"* (or *"JSON object array"*). [JSON](https://en.wikipedia.org/wiki/JSON) is a text representation of some data structure. One can store it in a file, send it through the network or even re-create the encoded data structure on a different computer and even using a different programming language. The value returned by [`json_decode($output, true)`](http://php.net/manual/en/function.json-decode.php) is an array. – axiac Oct 02 '17 at 11:43
  • Read about PHP [arrays](http://php.net/manual/en/language.types.array.php) and don't stop until to reach the section [*"Accessing array elements with square bracket syntax"*](http://php.net/manual/en/language.types.array.php#language.types.array.syntax.accessing). – axiac Oct 02 '17 at 11:43
  • Thanks, everybody, the linked question with it's answers was what I am looking for. I am sorry I didn't see that before. – Isabel Weber Oct 02 '17 at 15:13

0 Answers0