(apparent?) json validation problem in Data

My Flutter/Dart todo application has a Data table named TodoEntry with six columns: the ‘todos’ column is type json, four are string, one is datetime.

The data being stored is {username: jaustin@gmail.com, todos: {0: {title: milk, done: 0, created: 1638896985707}}, created: null, updated: null, objectId: null}, but Backendless sends back the error “PlatformException(8023, Validation for the ‘todos’ property failed. Property value does not match the required pattern., Validation for the ‘todos’ property failed. Property value does not match the required pattern., null)”.

The json column seems to be causing the error (“‘todos’ property failed”); if I change the todos column type to text the save works, although nothing shows in the todos column. The todos data {0: {title: milk, done: 0, created: 1638896985707}} shows as valid in an online json validator.

If I manually enter the json string through Multi Line Editor, it gives the message “Must be a valid JSON string!”!

Comments?

Hi Jim,

Welcome to the Backendless community. Are you formatting your JSON like this:

{0: {title: milk, done: 0, created: 1638896985707}}

or like this?

{"0": {"title": "milk", "done": 0, "created": 1638896985707}}

I just tried the latter version and it worked just fine. The reason being is the JSON key identifiers must be string literals. Here’s a SO discussion on this sibject:

Regards,
Mark

Thanks Mark, you’ve pointed me in the right direction. I (now) see the online json validator added the quotes to the keys and warned me; I just missed it.

The ‘correct’ line is still showing error: in my TodoEntry table the value
{“0”: {“title”: “milk”, “done”: 0, “created”: 1638896985707}} still causes Multi Line Editor to return
“Validation for the ‘todos’ property failed. Property value does not match the required pattern.”

If this is a known correct format for Backendless json validation, I’m wondering if the TodoEntry table has become corrupted. Should I delete and rebuild?
Jim

Hi Jim,

Have you tried adding that JSON doc manually using Backendless console? It would be a good test to make validate the actual JSON.

Regards,
Mark

Mark,
Yes, that’s where I’m getting the error: I simply copy/paste the json string you sent into the todos column in the console. No coding involved … think it’s time to delete the table and rebuild?
Jim

Jim,

Before you do that, let me give it a try. Please let me know your application ID.

Regards,
Mark

From the console: 6B43094C-5944-5D8A-FF17-CFAE0CED4500

Hi Jim,

I removed the todos column and recreated it in the table. There was something wrong with the column. Was it originally created as a JSON column or you converted it from another data type?

Then I tried copy/pasting the JSON from this forum and there is a problem with the quotes:

I fixed the quotes to use the proper double quote character and it works:
"

You can actually see the JSON data in the table.

Regards,
Mark

Thanks Mark, think that got it!! I was able to save a todo … looks like just after you did.

Yes, when couldn’t get the json type to save, tried text type, thinking I’d see the json string. Code did the save (username. etc.) but the todos column was empty. Went back and forth several times, so assumed that caused the problem. Just did another save (three items) and they all seem to be there.

Really appreciate your help … this one had me stumped!
Jim

Glad we got it working, Jim. It pointed out a use case we need to check (switching from Text to JSON). There may be an issue there.

Anyway, please don’t hesitate to contact us if you need any assistance.

Regards,
Mark

Mark,

FWIW, a few notes:

  • This current work with Backendless is through a Flutter tutorial by Johan Jurrius (https://www.youtube.com/c/JohanJurrius). The complete course playlist is at https://www.youtube.com/playlist?list=PLfNDfEpg5eOOxE6arbfrloHtieJ4aSY9v; the Backendless videos are at the end, 33-44.

  • Just before that is a sequence using SQLite (28-32), and I understand he’s working on a sequence using Firebase as the BaaS. The important thing (to me) is all three sequences use the same UI and are the ‘same’ app: a todo list that users register/log into and create, use, and delete todo items: a unique chance to compare the (Dart/Flutter) code for the same application using different authentication/storage methods.

  • Johan is hands-down the best teacher I’ve found in the on-line tutorial world. A number of years teaching at the university (UF) graduate level have left me with a lot of opinions about what’s good teaching and what’s not … there’s a lot of the latter out there in ‘Tutorial Hell!’

  • on a personal level, I’ve done several tutorial apps using Firebase, and am impressed by the smooth, straight-forward feel of the Backendless development process. Going to try to get to as many of the Missions as I can before the trial runs out.

Thanks again,

Jim