No validation if you post a content through API

System Information
  • 4.6.1:
  • Mac:
  • Postgresql:
  • 12:
  • 6:
  • 1.2:

I’m new here, but have a long web development background.
I just build a Strapi project and and add ONE content type with ONE JSON field.
And created an Access token to populate that JSON data through API

if you post the data in string format instead of JSON to that field, I can not access the content type at admin anymore, I see “An error occurred during models config fetch.”

The weird thing, content is created at data base. If you delete the record from database error is gone.

my question: don’t Strapi have a type validation, if you want to create it through API. Maybe I’m doing something wrong ?

I just figure out, same thing happens if you try to create the content through admin

{
  "data": {
    "basket": "some string"
  }
}

“basket” is JSON field type

I really wonder if there is a validation plugin ?

This sounds like a bug to me. If the field is defined as "type": "json" in the schema, I’d expect every link in the chain to validate that only JSON strings can be inserted. It sounds like during creation the validation is not happening and then when retrieving that value, the validation is happening.

I’ve just found a related github issue here:

Hello :slight_smile:
I think it will be fixed with Fix JSON field for postgres when the value is a simple string by petersg83 · Pull Request #15752 · strapi/strapi · GitHub

1 Like