insomnia-plugin-jsonpath
Advanced tools
Comparing version 1.0.1 to 1.0.2
63
index.js
const jq = require('jsonpath'); | ||
module.exports.templateTags = [{ | ||
displayName: 'JSONPath', | ||
name: 'jsonpath', | ||
description: 'Pull data from JSON strings with JSONPath', | ||
args: [{ | ||
displayName: 'JSON string', | ||
type: 'string' | ||
}, { | ||
displayName: 'JSONPath Filter', | ||
type: 'string' | ||
}], | ||
run (context, jsonString, filter) { | ||
let body; | ||
try { | ||
body = JSON.parse(jsonString); | ||
} catch (err) { | ||
throw new Error(`Invalid JSON: ${err.message}`); | ||
} | ||
module.exports.templateTags = [ | ||
{ | ||
displayName: 'JSONPath', | ||
name: 'jsonpath', | ||
description: 'Pull data from JSON strings with JSONPath', | ||
args: [ | ||
{ | ||
displayName: 'JSON string', | ||
type: 'string' | ||
}, | ||
{ | ||
displayName: 'JSONPath Filter', | ||
type: 'string' | ||
} | ||
], | ||
run(context, jsonString, filter) { | ||
let body; | ||
try { | ||
body = JSON.parse(jsonString); | ||
} catch (err) { | ||
throw new Error(`Invalid JSON: ${err.message}`); | ||
} | ||
let results; | ||
try { | ||
results = jq.query(body, filter); | ||
} catch (err) { | ||
throw new Error(`Invalid JSONPath query: ${filter}`); | ||
} | ||
let results; | ||
try { | ||
results = jq.query(body, filter); | ||
} catch (err) { | ||
throw new Error(`Invalid JSONPath query: ${filter}`); | ||
} | ||
if (results.length === 0) { | ||
throw new Error(`JSONPath query returned no results: ${filter}`); | ||
if (results.length === 0) { | ||
throw new Error(`JSONPath query returned no results: ${filter}`); | ||
} | ||
return results[0]; | ||
} | ||
return results[0]; | ||
} | ||
}]; | ||
]; |
{ | ||
"name": "insomnia-plugin-jsonpath", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": "Gregory Schier <gschier1990@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Template tag to pull data from JSON strings", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1804
36