Skip to content

Instantly share code, notes, and snippets.

@Pierozi
Created June 29, 2015 08:52
Show Gist options
  • Save Pierozi/6361d7f80d6379df472b to your computer and use it in GitHub Desktop.
Save Pierozi/6361d7f80d6379df472b to your computer and use it in GitHub Desktop.
JSON API Output with relationship included
{
"links": {
"self": "/examples/collection_advanced.php"
},
"data": [
{
"type": "user",
"id": "USER-A",
"attributes": {
"firstname": "John",
"lastname": "Doe",
"age": 35
},
"relationships": {
"addresses": {
"links": {
"self": "/user/USER-A/relationships/addresses",
"related": "/user/USER-A/addresses"
},
"data": {
"type": "addresses",
"id": [
"ADDR-A",
"ADDR-B"
]
}
},
"projects": {
"links": {
"self": "/user/USER-A/relationships/projects",
"related": "/user/USER-A/projects"
},
"data": {
"type": "projects",
"id": [
"PRJ-A",
"PRJ-B",
"PRJ-C"
]
}
}
},
"links": {
"self": "/user/USER-A"
}
},
{
"type": "user",
"id": "USER-B",
"attributes": {
"firstname": "Jane",
"lastname": "Smith",
"age": 26
},
"relationships": {
"addresses": {
"links": {
"self": "/user/USER-B/relationships/addresses",
"related": "/user/USER-B/addresses"
},
"data": {
"type": "addresses",
"id": [
"ADDR-C"
]
}
},
"projects": {
"links": {
"self": "/user/USER-B/relationships/projects",
"related": "/user/USER-B/projects"
},
"data": {
"type": "projects",
"id": [
"PRJ-A"
]
}
}
},
"links": {
"self": "/user/USER-B"
}
}
],
"included": [
{
"type": "addresses",
"id": "ADDR-A",
"attributes": {
"label": "Home",
"location": "42 rue des nerds"
},
"links": {
"self": "/addresses/ADDR-A"
}
},
{
"type": "addresses",
"id": "ADDR-B",
"attributes": {
"label": "Work",
"location": "1337 street center"
},
"links": {
"self": "/addresses/ADDR-B"
}
},
{
"type": "projects",
"id": "PRJ-A",
"attributes": {
"name": "Iced"
},
"relationships": {
"clients": {
"links": {
"self": "/projects/PRJ-A/relationships/clients",
"related": "/projects/PRJ-A/clients"
},
"data": {
"type": "clients",
"id": [
"CLT-A"
]
}
},
"tags": {
"links": {
"self": "/projects/PRJ-A/relationships/tags",
"related": "/projects/PRJ-A/tags"
},
"data": {
"type": "tags",
"id": [
"TAG-A",
"TAG-C"
]
}
}
},
"links": {
"self": "/projects/PRJ-A"
}
},
{
"type": "clients",
"id": "CLT-A",
"attributes": {
"name": "Lemon"
},
"links": {
"self": "/clients/CLT-A"
}
},
{
"type": "tags",
"id": "TAG-A",
"attributes": {
"name": "E-Commerce"
},
"links": {
"self": "/tags/TAG-A"
}
},
{
"type": "tags",
"id": "TAG-C",
"attributes": {
"name": "Cool"
},
"links": {
"self": "/tags/TAG-C"
}
},
{
"type": "projects",
"id": "PRJ-B",
"attributes": {
"name": "Fuel"
},
"relationships": {
"clients": {
"links": {
"self": "/projects/PRJ-B/relationships/clients",
"related": "/projects/PRJ-B/clients"
},
"data": {
"type": "clients",
"id": [
"CLT-B"
]
}
}
},
"links": {
"self": "/projects/PRJ-B"
}
},
{
"type": "clients",
"id": "CLT-B",
"attributes": {
"name": "Cake"
},
"links": {
"self": "/clients/CLT-B"
}
},
{
"type": "projects",
"id": "PRJ-C",
"attributes": {
"id": "PRJ−C",
"name": "Melon"
},
"relationships": {
"clients": {
"links": {
"self": "/projects/PRJ-C/relationships/clients",
"related": "/projects/PRJ-C/clients"
},
"data": {
"type": "clients",
"id": [
"CLT-A"
]
}
},
"tags": {
"links": {
"self": "/projects/PRJ-C/relationships/tags",
"related": "/projects/PRJ-C/tags"
},
"data": {
"type": "tags",
"id": [
"TAG-B"
]
}
}
},
"links": {
"self": "/projects/PRJ-C"
}
},
{
"type": "tags",
"id": "TAG-B",
"attributes": {
"name": "Accounting"
},
"links": {
"self": "/tags/TAG-B"
}
},
{
"type": "addresses",
"id": "ADDR-C",
"attributes": {
"label": "Home",
"location": "Luxembourg"
},
"links": {
"self": "/addresses/ADDR-C"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment