I have a JSON file that is valid, but I need to add quotes around the number values and boolean values in order to send this JSON to a wix repeater that requires quotes around them.
If anyone can assist me with this, I would greatly appreciate it.
Example of received JSON:
[{"id":1238890,"category_id":1,"season_id":14866,"venue_id":null,"referee_id":null,"slug":"2022-08-12-melbourne-knights-fc-altona-magic-sc","name":"Melbourne Knights FC – Altona Magic SC","status":"inprogress","time_details":{"prefix":"","initial":0,"max":2700,"timestamp":1660296540,"extra":540}, "_id":1}]
Example of needed JSON:
[{"id":"1238890","category_id":"1","season_id":"14866","venue_id":"null","referee_id":"null","slug":"2022-08-12-melbourne-knights-fc-altona-magic-sc","name":"Melbourne Knights FC – Altona Magic SC","status":"inprogress","time_details":{"prefix":"","initial":"0","max":"2700","timestamp":"1660296540","extra":"540"}, "_id":"1"}]
I attempted the code below to transform the json data, but did not achieve the desired outcome
J'ai essayé ce code là en transformant mon json en chaine string mais sans le résultat escompté..
const regex = /[^"\d,]?(\d+)/g;
const str = [{"id":"1238890","category_id":"1","season_id":"14866","venue_id":"null","referee_id":"null","slug":"2022-08-12-melbourne-knights-fc-altona-magic-sc","name":"Melbourne Knights FC – Altona Magic SC","status":"inprogress","time_details":{"prefix":"","initial":"0","max":"2700","timestamp":"1660296540","extra":"540"}, "_id":"1"}]
const subst = `:` + `"$1"`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Kind regards