{"id":30146520,"url":"https://github.com/apioo/psx-nested","last_synced_at":"2026-05-20T05:34:22.030Z","repository":{"id":149991062,"uuid":"622513043","full_name":"apioo/psx-nested","owner":"apioo","description":"Build complex nested data structures from relational tables","archived":false,"fork":false,"pushed_at":"2024-07-21T21:16:17.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-27T13:31:18.030Z","etag":null,"topics":["api","json","nested-structures","sql"],"latest_commit_sha":null,"homepage":"https://phpsx.org/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apioo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"chriskapp","patreon":"fusio","custom":"https://www.paypal.me/fusioapi"}},"created_at":"2023-04-02T10:45:58.000Z","updated_at":"2024-07-21T21:15:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"b04d648c-be3e-436a-b274-dda275cdfd13","html_url":"https://github.com/apioo/psx-nested","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/apioo/psx-nested","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-nested","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-nested/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-nested/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-nested/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apioo","download_url":"https://codeload.github.com/apioo/psx-nested/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-nested/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269864126,"owners_count":24487576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","json","nested-structures","sql"],"created_at":"2025-08-11T09:39:01.589Z","updated_at":"2026-05-20T05:34:22.024Z","avatar_url":"https://github.com/apioo.png","language":"PHP","funding_links":["https://github.com/sponsors/chriskapp","https://patreon.com/fusio","https://www.paypal.me/fusioapi"],"categories":[],"sub_categories":[],"readme":"\n# Nested\n\nThis library helps to build complex nested JSON responses based on relational tables.\n\n## Basic usage\n\nAt the core this library provides a `Builder` class which allows you to define a definition structure how the result\nof your JSON response should look. To give you an example the following code is from our test case and should give you\na first insight how you can generate a complex JSON structure s.\n\n```php\n\u003c?php\n\n$connection = null; // a doctrine DBAL connection\n$builder = new \\PSX\\Nested\\Builder($connection);\n\n$definition = [\n    'totalResults' =\u003e $builder-\u003edoValue('SELECT COUNT(*) AS cnt FROM psx_sql_provider_news', [], $builder-\u003efieldInteger('cnt')),\n    'entries' =\u003e $builder-\u003edoCollection('SELECT * FROM psx_sql_provider_news ORDER BY id DESC', [], [\n        'id' =\u003e $builder-\u003efieldInteger('id'),\n        'title' =\u003e $builder-\u003efieldCallback('title', function($title){\n            return ucfirst($title);\n        }),\n        'author' =\u003e $builder-\u003edoEntity('SELECT * FROM psx_sql_provider_author WHERE id = ?', [new Reference('author_id')], [\n            'id' =\u003e $builder-\u003efieldFormat('id', 'urn:profile:%s'),\n            'name' =\u003e 'name',\n            'uri' =\u003e 'uri',\n        ]),\n        'tags' =\u003e $builder-\u003edoColumn('SELECT title FROM psx_sql_provider_news', [], 'title'),\n        'date' =\u003e $builder-\u003efieldDateTime('create_date'),\n    ])\n];\n\n$result = $builder-\u003ebuild($definition);\n\necho \\json_encode($result);\n\n```\n\nThis would result in the following JSON payload \n\n```json\n{\n  \"totalResults\": 2,\n  \"entries\": [\n    {\n      \"id\": 2,\n      \"title\": \"Bar\",\n      \"author\": {\n        \"id\": \"urn:profile:1\",\n        \"name\": \"Foo Bar\",\n        \"uri\": \"https:\\/\\/phpsx.org\"\n      },\n      \"tags\": [\n        \"foo\",\n        \"bar\"\n      ],\n      \"date\": \"2016-03-01T00:00:00Z\"\n    },\n    {\n      \"id\": 1,\n      \"title\": \"Foo\",\n      \"author\": {\n        \"id\": \"urn:profile:1\",\n        \"name\": \"Foo Bar\",\n        \"uri\": \"https:\\/\\/phpsx.org\"\n      },\n      \"tags\": [\n        \"foo\",\n        \"bar\"\n      ],\n      \"date\": \"2016-03-01T00:00:00Z\"\n    }\n  ]\n}\n```\n\n## JSON Definition\n\nIt is also possible to declare the definition in a JSON notation\n\n```json\n{\n  \"totalEntries\": {\n    \"$value\": \"SELECT COUNT(*) AS cnt FROM psx_sql_provider_news\",\n    \"$definition\": {\n      \"$key\": \"cnt\",\n      \"$field\": \"integer\"\n    }\n  },\n  \"entries\": {\n    \"$collection\": \"SELECT id, author_id, title, create_date FROM psx_sql_provider_news ORDER BY id ASC LIMIT :startIndex, 8\",\n    \"$params\": {\n      \"startIndex\": 0\n    },\n    \"$definition\": {\n      \"id\": {\n        \"$key\": \"id\",\n        \"$field\": \"integer\"\n      },\n      \"title\": \"title\",\n      \"tags\": {\n        \"$column\": \"SELECT title FROM psx_sql_provider_news\",\n        \"$definition\": \"title\"\n      },\n      \"author\": {\n        \"$entity\": \"SELECT id, name, uri FROM psx_sql_provider_author WHERE id = :id\",\n        \"$params\": {\n          \"id\": {\n            \"$ref\": \"author_id\"\n          }\n        },\n        \"$definition\": {\n          \"displayName\": \"name\",\n          \"uri\": \"uri\"\n        }\n      }\n    }\n  }\n}\n```\n\nThen you can execute this JSON definition through the JSON provider\n\n```php\n\u003c?php\n\n$json = '{}'; // JSON from above\n\n$provider = new JsonProvider($this-\u003econnection);\n$result = $provider-\u003ecreate(\\json_decode($json));\n\necho \\json_encode($result);\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapioo%2Fpsx-nested","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapioo%2Fpsx-nested","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapioo%2Fpsx-nested/lists"}