-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON column with Unicode emojis breaks #56
Comments
Hi Martin, According to this article, the default behavior of |
Hi Adalbert Thanks for your input. Actually, the docs make me a bit more confused. It says, only the Basic Multilingual Plane is supported in JSON columns, but the emoji from my example uses the U+1F600 codepoint (Supplementary Multilingual Plane). However, it seems supported when not escaping the character with backslashes.
|
hi there, i can confirm this problem. <SubTitle>TOP PREIS ❗️ BESTE QUALITÄT 😍 KOSTENLOSE LIEFERUNG ✔</SubTitle> I convert this to an array and from there I do json_encode($array,true) in a native JSON column, the smiley is broken, but if I store the JSON into a LONGTEXT, everything works fine here´s a sandbox of what I do: https://phpsandbox.io/n/singlestore-json-example-tg36z I contacted singlestore support, and they told me:
so I guess the problem is related to this package, somehow. @AdalbertMemSQL I would be happy, if you could take a look into this issue (again). THANKS! |
and yes, i can confirm, if I use my own "custom Cast" like this: protected $casts = [
'body' => Json::class,
];
// Casts/Json.php
class Json implements CastsAttributes
{
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
{
return json_decode($value, true, 512, JSON_INVALID_UTF8_IGNORE);
}
public function set(Model $model, string $key, mixed $value, array $attributes): string|false
{
return json_encode($value, JSON_UNESCAPED_UNICODE);
}
} I see a correct smiley in my singlestore json column. |
Thanks, @michabbb |
after testing some more, i start thinking, that singlestore only supports "UNESCAPED UNICODE", because inserting a string like this: {"SubTitle":"TOP PREIS \u2757\ufe0f BESTE QUALIT\u00c4T \ud83d\ude0d KOSTENLOSE LIEFERUNG \u2714"} simply is not working. i asked the singlestore support, will update this posting, if I got feedback. btw.... laravel offers no support for adding any options to auto-casts like array<->json - "json_encode", I guess that´s why there are "custom casts" 😏 |
Just jumping in here to say that we've been fighting with the exact same issue, and hanging in here for any follow up! |
A small update regarding this. That's why 😀 (0x1F600) doesn't work well. There is a ticket to fix this on the database side.
Such characters still work well when they are not escaped
So, in conclusion, characters from the Basic Multilingual Plane work well
+------------+
| data |
+------------+
| {"a":"ם"} |
+------------+
1 row in set (0.009 sec) but characters outside of the Basic Multilingual Plane should be used with the JSON_UNESCAPED_UNICODE flag until their support is added to the database
+--------------+
| data |
+--------------+
| {"a":"😀"} |
+--------------+
1 row in set (0.019 sec) |
Any updates on this? |
The database still does not support escaped characters outside the Basic Multilingual Plane in JSON |
Inserting emojis becomes ������ in JSON columns.
Using the
JSON_UNESCAPED_UNICODE
flag seems to work:This affects Eloquent models with JSON casting attributes (like
array
andobject
).Is this related to Laravel, PDO MySQL driver, or SingleStore DB?
Normally, I would expect the stored JSON value to use backslashes to escape Unicode characters (PHP default with
json_encode
), but that does not seem to be the way SingleStore DB handles it.The text was updated successfully, but these errors were encountered: