Let's us consider you have string like
example : "name:lucy,age:21,gender:female"
function getJsonData(query){_x000D_
let arrayOfKeyValues = query.split(',');_x000D_
let modifiedArray = new Array();_x000D_
console.log(arrayOfKeyValues);_x000D_
for(let i=0;i< arrayOfKeyValues.length;i++){_x000D_
let arrayValues = arrayOfKeyValues[i].split(':');_x000D_
let arrayString ='"'+arrayValues[0]+'"'+':'+'"'+arrayValues[1]+'"';_x000D_
modifiedArray.push(arrayString);_x000D_
}_x000D_
let jsonDataString = '{'+modifiedArray.toString()+'}';_x000D_
let jsonData = JSON.parse(jsonDataString);_x000D_
console.log(jsonData);_x000D_
console.log(typeof jsonData);_x000D_
return jsonData;_x000D_
}_x000D_
_x000D_
let query = "name:lucy,age:21,gender:female";_x000D_
let response = getJsonData(query);_x000D_
console.log(response);
_x000D_
`