-1

I have a nested json string like below for which I need to append double quotes for each key and value

{messageFilters:[{filterCriteria:[{paramNameAndVals:{},values:[abc[0-9]],context:Request,name:Destination-Host,operator:abc}],filterActions:[{paramNameAndVals:{Set Name:sdf,Value To Hash:as},context:Context,name:Stick-To-Pool}],name:MF}],name:fg1,subGroups:[],advancedView:false}

I want below output like ,

{"messageFilters":[{"filterCriteria":[{"paramNameAndVals":{},"values":["abc[0-9]"],"context":"Request","name":"Destination-Host","operator":"abc"}],"filterActions":[{"paramNameAndVals":{"Set Name":"sdf","Value To Hash":"as"},"context":"Context","name":"Stick-To-Pool"}],"name":"MF"}],"name":"fg1","subGroups":[],"advancedView":false}

I tried various regex patterns, but evrerything in vain. Could anyone please help

Ashok Cj
  • 21
  • 2
  • 1
    how are you creating your json? – Scary Wombat Mar 13 '19 at 07:10
  • Json is created through CDL.toString() method. The above json is actually an inner class, I am trying to import CSV file which has other columns as well and this is one of the column value and CDL.toString() is returning the entire value as json string . – Ashok Cj Mar 13 '19 at 07:19
  • what on earth is CDL? – Scary Wombat Mar 13 '19 at 07:25
  • org.json.CDL is the package and it provides various static methods to convert CSV to jsonArray and vice-versa. – Ashok Cj Mar 13 '19 at 07:35
  • I cannot change the design right now as i have to support backward comaptibility. All I am looking for is a regex which will help me achieve this ! – Ashok Cj Mar 13 '19 at 07:36
  • as per javadocs *This provides static methods to convert comma delimited text into a JSONArray, and to covert a JSONArray into comma delimited text.* – Scary Wombat Mar 13 '19 at 07:38
  • Ok basically first we are exporting the data in CSV format and output gives me as json only for inner class . And when I try to import it back I want to convert the json string in question to actual json object ,I tried using Gson, passing the string as constructor parameter for JSONObject for all trials I am getting parse exception for ",values:[abc[0-9]] " this parameter. Hence I need to effectively append double quotes in order to convert it into JSONObject. – Ashok Cj Mar 13 '19 at 07:48

1 Answers1

0

the first example of your question is not a valid json, try convert your not valid json to string. kindly chechk this link for more information How to convert any Object to String?