Unexpected token N in JSON at position 0

Wappler Version : 5.2.1
Operating System : Windows
Server Model: NodeJS
Database Type: Mariadb

What do you think should happen?

I realize that parseJSON cause error.

Before updates to 5.2.1 my page worked normally.
In Server Action:
Set Value = query.config_value.parseJSON() with no error:

At same time.
In UI a dynamic JSON value comes from SC works normally wihout using .toJSON().

What actually happens?

After update to v5.2.1
In server actions if exists any Set Value with .parseJSON outputs it throws the error., e.g…

Set Value = query.config_value.parseJSON() throws next error:


If I remove the .parseJSON() the error disappears.
Set Value = query.config_value

At same time:
In UI a dynamic JSON value comes from SC it’s mandatory to use .toJSON() without it cause [object Object]

Temp workaround to solve this

Fortunately I don’t have much JSON parse in SC and UI, so, I just remove it.

Would be great to know if this will keep permanent from now or I should later have to revert this again?

Other option is downgrade the files from the new v5.2.1
Not uninstall Wappler just replace this files:

image
v5.2.0.zip (34.5 KB)

Where did you use the toJSON() formatter? Did you use it to parse a JSON string or is it for the value returned from a JSON field in the database. The JSON database field should not need to be parsed, there were some databases where this didn’t happen and that should now have been fixed. When you insert into a database JSON field you can just use the array/object directly and reading the data should return the array/object again. This worked on most databases correctly and the last update fixed this behavior for the databases not parsing it correctly.

It’s from a JSON field from database.

image

Until version 5.2.0 for me was neccesary to use .parseJSON() otherwise I obtained an escape json format.

{\"variable\": \"nueva_lib_54\", \"data_type\": \"INSERT\", \"creado_por\": \"2\", \"fecha_hora\": \"2022-10-18 07:22:33\", \"cod_usuario\": \"ce8d8a0b-69f8-4c48-a55f-f6b46b4e8ced\", \"rol_usuario\": \"Administrador\", \"nombre_usuario\": \"Alexander Paladines\", \"valor_variable\": \"Valor de lib 54\"}

In SC I query the JSON field from database and output with a Set Value = query.config_value.parseJSON()
Then in UI I use this to show the same JSON field in a modal but pretty with format using a “JSON.stringify” with the help of this tiny script:

<script>
  function prettyPrint() {
  var ugly = document.getElementById('json_full').value;
  var obj = JSON.parse(ugly);
  var pretty = JSON.stringify(obj, undefined, 4);
  document.getElementById('json_full').value = pretty;
  }
</script>

Now in this new version I see that this is not neccesary any more because the field is now parsing without declare parseJSON().
But my question now is if this will be permanent or will change in next version.
Right now I downgrade the files from new version to keep things like before, but if this will keep permanent I could upgrade without worry about it again.

This change will be permanent, as I mentioned it was already default for most databases and the correct behavior, I believe only mySQL on NodeJS didn’t return the JSON fields correctly, this has now been fixed.

There’s an \n at position 0. You may want to ensure that’s been \ escaped

It should not be escaped in the database unless it was stringified 2 times on insert. Will check the insert/update behavior also.