I can't figure out how to set proper encoding for json data.
I get some contents from API:
{"id":6889,"name":"IV liga \u015bl\u0105ska I"}
{"id":6890,"name":"IV liga \u015bl\u0105ska I"}
On the PHP side, I save this data to MySQL. Just before writing to database, the data has the correct form (like above).
I created table.
CREATE TABLE IF NOT EXISTS `tab_name` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`content` JSON NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
And I executed two insert command. First command is without escaping and to second command I added backslash.
INSERT INTO `tab_name` (`content`) VALUES('{"id":6889,"name":"IV liga \u015bl\u0105ska I"}');
INSERT INTO `tab_name` (`content`) VALUES('{"id":6889,"name":"IV liga \\u015bl\\u0105ska I"}');
In result I get only the last row which is correct.
SELECT content->'$.name' as name from tab_name;
| name |
+----------------------------+
| "IV liga u015blu0105ska I" |
| "IV liga śląska I" |
Other solution: preg_replace()?
Please help.