-3

I have a string like below which can grow further with few more AND/OR/NOT condition but maintains the syntax.

String string = "apple,mango,name(
        AND(
              OR(
                  gender[male,female],
                  county[USA,India]
              ),
             language[spanish,english],
             education[masters,bachelors],
             NOT(
                 education[Phd]
             )
        )
     ),orange"

Need to parse this string. partially successful to convert this string as JSON object. But couldn't do it completely.

1 Answers1

0

You can easliy convert this to a rough json string. A quick sample would be

String json = "{"+string.replace("(",":{").replace("[",":[").replace(")","}")+"}";

Of course you would need to add to this to make it a valid json by inserting quotes as necessary " or ' .

Once you have JSOn you would be able to easily convert this to a java object. Check Jackson or GSON libraries.

jozzy
  • 2,863
  • 3
  • 15
  • 12