I'll like to split the JSON object below to its respective keys and value using regular expression and wrap the values in a html p tag.
{
"completeOrder": [
{
"optionDescription": "Choose your size?",
"optionTotal": 3,
"dataMax": 0,
"name": [
"wheat",
" dough",
" rice"
],
"price": [
"34",
"23",
"45"
],
"require": false,
"dataSingleproduct": false,
"innerOptions": [],
"extraOptions": [
...
]
}
]
}
The returned string i want would look like this:
{
completeOrder: [{
optionDescription:
<p>Choose your size</p>
optionTotal:
<p>3</p>
dataMax:
<p>0</p>
name: [
<p>Wheat</p>
...
]
...
]
}
This JSON object is saved in a file, received via node.js's "fs.read" feature. I receive the object in str variable, presently this is the code i have presently, its giving me close to what i want but it lacks the form i need.
let val= str.split(/[\r\n|\r|\n|{|}|:|,|\[|\]]/gi);
for (let i = 0; i < val.length; i++) {
// if(sentences[i] !== ""){
console.log(val[i])
// }
}
My code strips the of the characters ("{", "[", "]", "}", ":") but i dont what them stripped. Any help would be appreciated