Skip to content

Instantly share code, notes, and snippets.

@FrontierPsychiatrist
Last active April 20, 2017 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrontierPsychiatrist/ce72fcb35196b8edb6b5d807a1080b8f to your computer and use it in GitHub Desktop.
Save FrontierPsychiatrist/ce72fcb35196b8edb6b5d807a1080b8f to your computer and use it in GitHub Desktop.
Postgres JSON for API responses
CREATE TABLE api_responses (
name VARCHAR,
body JSONB
);
INSERT INTO api_responses (name, body)
VALUES ('request-x', '{ "id": 1234, "data": { "people": [ { "name": "Moritz", "github": "FrontierPsychiatrist" }, { "name": "Alexander", "github": "alexhanschke" } ] } }');
SELECT people->'name', people->'github'
FROM api_responses, jsonb_array_elements(body->'data'->'people') people WHERE name = 'request-x';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment