更改嵌套的键名 JSON mysql
Change Key Name in nested JSON mysql
我想更改mysql中JSON的第一级和第二级的Key Name。
为此,我有一个名为 content
的 table 和一个名为 attribs
的列,存储的数据如下:
{"author": "Nika", "link_url": "", "gallery": "{\"gallery_images\":[\"images/2017/09/30/blog_011.jpg\",\"images/2017/09/30/blog_010.jpg\",\"images/2017/09/30/blog_009.jpg\"]}", "show_urls": ""}
我希望它是这样的:
{"post_author": "Nika", "link_url": "", "gallery": "{\"post_gallery_images\":[\"images/2017/09/30/blog_011.jpg\",\"images/2017/09/30/blog_010.jpg\",\"images/2017/09/30/blog_009.jpg\"]}", "show_urls": ""}
总而言之,我想将 author
更改为 post_author
,将 gallery_images
更改为 post_gallery_images
更新:我试过以下;但它只改变第一级。我在 Whosebug 中的 Mysql 文档和答案中尝试了其他方法,但在第二级没有尝试。
UPDATE adneit_content SET attribs = REPLACE(attribs, '"author":', '"post_author":');
谢谢。
要更新嵌套键,您还需要匹配反斜杠。
UPDATE adneit_content
SET attribs = REPLACE(
REPLACE(attribs, '"author":', '"post_author":'),
'\"gallery_images\":', '\"post_gallery_images\":')
我想更改mysql中JSON的第一级和第二级的Key Name。
为此,我有一个名为 content
的 table 和一个名为 attribs
的列,存储的数据如下:
{"author": "Nika", "link_url": "", "gallery": "{\"gallery_images\":[\"images/2017/09/30/blog_011.jpg\",\"images/2017/09/30/blog_010.jpg\",\"images/2017/09/30/blog_009.jpg\"]}", "show_urls": ""}
我希望它是这样的:
{"post_author": "Nika", "link_url": "", "gallery": "{\"post_gallery_images\":[\"images/2017/09/30/blog_011.jpg\",\"images/2017/09/30/blog_010.jpg\",\"images/2017/09/30/blog_009.jpg\"]}", "show_urls": ""}
总而言之,我想将 author
更改为 post_author
,将 gallery_images
更改为 post_gallery_images
更新:我试过以下;但它只改变第一级。我在 Whosebug 中的 Mysql 文档和答案中尝试了其他方法,但在第二级没有尝试。
UPDATE adneit_content SET attribs = REPLACE(attribs, '"author":', '"post_author":');
谢谢。
要更新嵌套键,您还需要匹配反斜杠。
UPDATE adneit_content
SET attribs = REPLACE(
REPLACE(attribs, '"author":', '"post_author":'),
'\"gallery_images\":', '\"post_gallery_images\":')