Dump page's content into json


first of all: i know there is content representation etc; but i need to dump the whole content of a page into an array of json objects.

my use case for this is to produce the same data structure that using kirby’s official APIs would do, but as i need to compose frontend pages from 3-4 kirby pages, and currently kirby does not allows to do multi-page API calls, so i need to cut on the http call time somehow…

i came across the dump helper which is kinda doing what i need, but it always start the dump with:

<pre>Kirby\Cms\Content Object( /* dump content */ ...

how do i just grab the inside of the Object (…)?



i get why dump() is printing that extra infos, makes sense.

i also tried to do directly something like


but i get back this


and if i directly call a field, eg


it returns back the value correctly.

somehow i want to automatically print all the field of a page, including files etc, in the same way that the kirby APIs is doing that :smiley:


Or if you need the complete page object:


You could use a route that loops through the pages you need and generates the JSON in exactly the format you want. I think you can also protect this, so that only a logged in user can reach the route, depending on what you need. I guess if its page content anyway, it’s fine for it to be public.

thanks! this is great!

i’ll craft something ad-hoc to get all those nice file infos for images etc, but it’s basically what i need.


yeah i might add a guard in the api call. though also yes, it’s public data, so not really a big concern :smile: