Skip to content

Processing json object received via sqlpage.fetch() #787

Answered by lovasoa
rstocks asked this question in Q&A
Discussion options

You must be logged in to vote

The various json functions documented in the article are not restricted to working with values coming from the database, and they work just as well with values coming from SQLPage.

Example

Here is an example using SQLite json functions to display an array from inside an API call result as a list using the default sqlpage list component :

set api_results =
    sqlpage.fetch('https://pokeapi.co/api/v2/pokemon?limit=10');

select 'list' as component, 'Pokémons' as title;
select 
    value->>'name' as title,
    value->>'url' as link
from json_each($api_results->'results');

(using https://pokeapi.co/ as an example api)

Results

https://editor.datapage.app/edit

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rstocks
Comment options

@lovasoa
Comment options

Answer selected by rstocks
@rstocks
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants