0

Is there a way to check if a given Java String conforms to the format of a JavaScript object literal?

For e.g.,

String foo = "{ name1: value, name2: value2 }";

The String is not a JSON Object i.e. name1, name2, value1, value2 are not in double quotes. Is there a way to test if foo is a valid object literal?

Thanks, Sony

sony
  • 1,557
  • 10
  • 36
  • 50
  • 1
    I think you have to have a JavaScript parser handy, if your object literals can be any sort of valid JavaScript. Note that property values in an object literal can be function instantiations, array literals, other object literals, etc. – Pointy Mar 04 '12 at 00:02

1 Answers1

0

You can try to write some regular expression for this purpose

Regex to validate JSON

Community
  • 1
  • 1
Shurok
  • 195
  • 1
  • 9