My WordPress website has an API that exports posts as a Json file. I am working on a new website that will use this data, but I need to reformat the Json file with my custom property names and exclude some properties. Here is an example of the Json output from a post:
{
"status": "ok",
"post": {
"id": 2335,
"type": "post",
"slug": "litoral-awards14-no-jornal-diario-porto-canal",
"url": "https:\/\/litoralmagazine.com\/litoral-awards14-no-jornal-diario-porto-canal\/",
...
}
}
I want to create a script that transforms this Json into a new format like below:
{
"status": "ok",
"slug": "litoral-com-teste-noticia-url",
"title": "Titulo de teste",
"type": "post",
...
}
}
For instance: originalJson.status = newJson.status, originalJson.author.id = newJson.author, originalJson.thumbnail.url = newJson.images.thumbnail_image.
In the original Json, the 'content' property contains HTML code which I want to remove when creating the new Json. How can I achieve this?
I have searched for solutions but haven't found any. Is there a JavaScript script that can take the old Json input and output a new Json file with customized properties as described above?
Any help or suggestions would be greatly appreciated. Thank you!