System Information
- Strapi Version: 3.4.1
- Operating System: Docker
- Database: mySQL 5.7.32
- Node Version: 14.15.3
- NPM Version: 6.14.9
- Yarn Version: 1.22.5
Hello
I registered a custom field via plugin (based on Creating a new Field in the administration panel).
As my field has a quite complex data structure, I did JSON.stringify(newValue)
to hand on the value as a stringified object to the content-manager. On receiving the value, I did JSON.parse(value)
to work with data. Also I parsed the value in every find or findOne of the controller of the content-type using this custom field in its model.
All good so far and working like a charm.
But I was wondering how JSON data is handled natively in strapi. And if there would be a way to provide interoperability (for example working on the controller does not feel right, can’t this all be configured in the plugin itself?).
I found out that in https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-content-manager/admin/src/components/InputJSON/index.js the returned object on change included a type: 'json'
{
target: {
name,
value,
type: 'json',
},
}
So I replaced my value: JSON.stringify({...})
with value, type: 'json'
which worked and left processing the input data to strapi. In mySQL the value is saved as a longtext.
But when receiving the value, it is still a string. As I recognized, no line of code in the InputJSON mentioned above parses the value, I guess this must have happened somewhere else.
Where? Or what do I have to do to receive value
as JSON object?
Is there something in the fieldAPI to tell that this custom field type should be interpreted like type json?