MariaDB JSON fields become text type

I wanted to create a json database field, so I changed the variable type to json. When I tried to apply this changes, that variable was changed back to text type. Is this a bug ?

What type of database do you use? Not all support json types.

Also there is no additional support for actions on json data types, so it’s usefulness might be limited.

Maybe explain why you need json data type in first place.

I have a field which has key fields.

monday: {
    day:"Monday",
    time:"12.00 PM"
}

I have 7 more similar table fields, And it is particular to a user. So, I want the json type to store key fields under a same field like above.

I am using MySQL database.

You should really try to save only core date types in database and do all formatting on the client side on display.

How should I store the data in database ?

Maybe this will help:

This is still a problem for me. I’m trying to create a json field but it keeps changing it back to a text field.

Screenshot 2022-04-08 at 16.55.12

Any chance this will be fixed in today’s update?

we have no problems in creating json fields…

How are you creating it? a new one or do you change existing type to json?

It happens either way. It holds the change until I apply it then it reverts back to TEXT with ‘NULL’ as the Default value.

I’m on the latest Wappler (M1).

What’s your database? MySQL/MariaDB has no JSON data type (as far as I remember) and therefore it (kinda) makes sense it gets converted to text/string

I kindly ask the Wappler team to confirm my theory, and your confirmation this is not a PostgreSQL database

You could be onto something there. phpMyAdmin shows json as a field type but if I select it, the field becomes longtext. It’s a MariaDB (10.4.14-MariaDB-log) database.

@George - will all the new functionality for json fields be available in Wappler if using MariaDB or MySQL?

Please check:

So it seems Wappler might see it as longtext instead of JSON (which is actually an alias and not a data type).

Maybe the comment field could be used to cast the type to JSON, or Wappler could perform an explicit check on the database to see if it’s a JSON type (whatever method phpMyAdmin is using to tell you it’s JSON)

Thanks Teodor. Can you confirm how Wappler handles this? I have gone down a path on a project to use the new json field type for storing multiple IDs and need to know if I should change all this and go back to my previous method of using many-to-many tables.

Seems to be an issue with MariaDB only - JSON data types are stored there as LONGTEXT fields …
Will see if we can improve this

1 Like

Should I abandon my use of json fields for many-to-many and go back to using tables?

Well with the new sub tables and multi references (junction tables for many-to-many), it is much easier to use those indeed. It will also give you better referential integrity

1 Like