I have a requirement to modify a JSON to a JSON having the values in a SQL query format. To better explain.
{
"Assets": {
"ASSOCIATES_NAME": ["David", "Philip"],
"CAR_NAME": ["Verron"]
}
, "Product":{"SELLER_NAME": ["XXXXX"]}
}
The result should be having the json values as an sql query leaving the keys as it is. So the resulting query will be:
{
Assets: "(ASSOCIATES_NAME = 'David' OR ASSOCIATES_NAME = 'Philip') AND CAR_NAME = 'Verron'",
Product: "SELLER_NAME = 'XXXXX'"
}
I tried something but I couldn't figure it out well. Below it is:
console.log(Object.entries(a).map(x => {return {
[x[0]]: `${Object.keys(x[1])} = '${Object.values(x[1])}'`,
}}))
However I still need to figure out how to group individual values of an array. Any elegant ES6 based solution to this?. Please folks help me out on this. TIA
JSON.parse. Also, I'm not sure why you would need regex in this situation.