Added JSONPath tests & changed lib

This commit is contained in:
Matt C committed 2017-08-03 14:50:16 +01:00
1 parent e0905255ba
commit 31bfd8664a
6 files changed
+6886 -13

No files matched your search

+1 -1
View File
@@ -2244,7 +2244,7 @@ const OperationConfig = {
]
},
"JPath expression": {
description: "Extract information from a JSON object with an JPath query",
description: "Extract information from a JSON object with a JPath query.",
run: Code.runJpath,
inputType: "string",
outputType: "string",
File diff suppressed because it is too large. Load diff
+9 -6
View File
@@ -4,7 +4,7 @@ import Utils from "../Utils.js";
import vkbeautify from "vkbeautify";
import {DOMParser as dom} from "xmldom";
import xpath from "xpath";
import jpath from "node-jpath";
import jpath from "../lib/jsonpath.js";
import prettyPrintOne from "imports-loader?window=>global!exports-loader?prettyPrintOne!google-code-prettify/bin/prettify.min.js";
@@ -377,16 +377,19 @@ const Code = {
*/
runJpath: function(input, args) {
let query = args[0],
delimiter = args[1];
let obj;
delimiter = args[1],
results,
obj;
try {
obj = JSON.parse(input);
} catch (err) {
return "Invalid input JSON.";
}
let results = jpath.filter(obj, query);
try {
results = jpath.query(obj, query);
} catch (e) {
return "Invalid JPath expression.";
}
return results.map(result => JSON.stringify(result)).join(delimiter);
},