Skip to content

Commit

Permalink
Fix json.path functions adding extra / and \ to json objects (#693)
Browse files Browse the repository at this point in the history
- Fix issue raised in #612
  • Loading branch information
Merudo authored and JamzTheMan committed Sep 15, 2019
1 parent f72af71 commit 4dd3334
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
String jsonStr = parameters.get(0).toString();
String path = parameters.get(1).toString();
Object value = parameters.get(2);
Object json = convertToJSON(value.toString());
if (json != null) value = json; // to prevent quotes getting turned into \" and \"

try {
return JsonPath.parse(jsonStr).add(path, value).jsonString(); // add element to array
Expand All @@ -128,6 +130,8 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
String jsonStr = parameters.get(0).toString();
String path = parameters.get(1).toString();
Object value = parameters.get(2);
Object json = convertToJSON(value.toString());
if (json != null) value = json;

try {
return JsonPath.parse(jsonStr).set(path, value).jsonString(); // set element in array/object
Expand All @@ -143,6 +147,8 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
String path = parameters.get(1).toString();
String key = parameters.get(2).toString();
Object value = parameters.get(3);
Object json = convertToJSON(value.toString());
if (json != null) value = json;

try {
return JsonPath.parse(jsonStr).put(path, key, value).jsonString(); // add value in object
Expand Down

0 comments on commit 4dd3334

Please sign in to comment.