0

I like to respond a Json like this

'{"name":"John", "age":30, "car":null}'

How is this possible with thos class:

https://github.com/joomla/joomla-cms/blob/4.2-dev/libraries/src/MVC/View/JsonApiView.php

It looks as I only can have link, data and jsonapi at the first Level of the JsonResponse.

4
  • 1
    Does JSON:API even allow that? Maybe you need generic JSON output instead?
    – Sharky
    Dec 20, 2022 at 8:12
  • Thank you. You are right, this not allowed: jsonapi.org/format/#document-top-level . How is the recommanded way to realise an output like this in Joomla? Is there an example?
    – agi
    Dec 20, 2022 at 8:34
  • Do you need this in the API application? Or in site/administrator?
    – Sharky
    Dec 21, 2022 at 20:22
  • I have not been able to solve this in the api yet either. I have used the view to a component like here: github.com/joomla/joomla-cms/tree/4.2-dev/administrator/… .
    – agi
    Dec 22, 2022 at 12:53

1 Answer 1

1

Joomla\CMS\MVC\View\JsonApiView view class is meant for generating JSON:API compliant output. For generic/custom JSON you can use the Joomla\CMS\MVC\View\JsonView class instead.

1
  • Is more tricky than that I think. I was trying get it done, and not work so far. Even when all is working (the controller connect with the view....etc) the result is a empty array []. Also, the headers output still application/vnd.api+json not matter what you try to change to the Document in the JsonView.... Dec 21, 2022 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.