So I'm testing my json validator and have json in my propertis file like:
jsonSource = {"kind": "Listing\""}
I get it with spring @Value("${jsonSource}")
run it through:
try {
gson.fromJson(jsonSource, Object.class);
return true;
} catch(com.google.gson.JsonSyntaxException ex) {
return false;
}
or
try {
new JsonParser().parse(jsonSource);
return true;
} catch (JsonParseException e) {
return false;
}
And it dosen't validate.
I tried jsonSource.replaceAll("\\", "\\\\");
on that string but no use.
I get my escaped json from http://www.reddit.com/r/IAmA.json (self_text) part
I guess I'm missing something really basic here, like what's happening under the hood with strings or how one should use json.
I'm interpreting this:
So I'm testing my json validator and have json in my propertis file like:
jsonSource = {"kind": "Listing\""}
As meaning you have a straight Java properties file which you're loading in a normal way. In that case, your string will be as if you'd written Java source code of:
String value = "{\"kind\": \"Listing\"\"}";
in other words, the string itself will contain:
{"kind": "Listing""}
Backslash in a properties file is used as an escape character - you need to double it if you want it to be in your actual string:
jsonSource = {"kind": "Listing\\""}
See more on this question at Stackoverflow