How can I change the field output for JSON:API?

Created on 17 May 2022, over 2 years ago
Updated 18 October 2023, about 1 year ago

Problem/Motivation

I'm using the JSON Field module and I have added a JSON field to my site. In the field settings, I set the field to "store as raw JSON in the database", but since I am using mariadb, it is actually stored as text.

The problem is that when I access this field via the core JSON:API, I get a string, not JSON. So I'm looking for a way to convert the string to "real" JSON before output by JSON:API.

I checked the customizing resources documentation but none of the methods there seemed like they would help in this case.

I'd appreciate it very much if someone could point to what I need to extend to get my JSON Field module JSON fields to automatically be output as JSON when accessed from JSON:API.

💬 Support request
Status

Fixed

Version

9.5

Component
JSON API 

Last updated 6 days ago

Created by

🇯🇵Japan ptmkenny

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany ro-no-lo

    For anybody comming here from Google, like me, you can achieve this with the jsonapi_extras module. There is config page "JSON:API Resource overrides" were you can choose to override settings. To do so you choose the entity and click the override button. Then choose the json_raw field of your liking and go to "Advanced" and pick the enhancer "JSON Field".

    After that, at least for me, the result of an json_field in the JSON:API was pure JSON.

    (I still have to test, if the POST and PATCH will handle the pure JSON as well, but ready pure JSON is a great start)

Production build 0.71.5 2024