Skip to content

JSON type - Encoding issue #1228

Closed
Closed
@deniapps

Description

@deniapps

We have JSON Type data field with some Latin characters, for example: "açaí". We used to use node-mysql, which queries the JSON filed as String, and we use JSON.parse to get the JSON object, which returns the correct character set, i.e. "açaí".

We switched to node-mysql2, and used typeCast to skip auto JSON parsing, like this:

typeCast: (field, next) => {
   if (field.type === 'JSON') {
      return field.string();
   }
   return next();
}

Everything works fine, but it does not handle encoding correctly, in the case, "açaí" is displayed as "açaí".

I am wondering how field.string() works. Does it use "UTF-8"? Can we return the JSON field using String as node-mysql does?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions