jsonata-extended
v0.4.2
Published
Extended JSONata object with custom functions
Downloads
6
Readme
jsonata-extended
Extended JSONata object with custom functions
This can be used to add extended functions to the standard JSONata
It has the same signature as the standard and so can be used as a dropin replacement.
Installation
npm install jsonata-extended
Example - Node
// const jsonata = require('jsonata');
const jsonata = require('jsonata-extended');
const expr = jsonata(
'$htmltotext("<p>Leadership has a dark side; a "leadership shadow" that often creates an unknown; lurking fear.</p>")'
);
const result = expr.evaluate();
Example - Browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JSONata Extended Test</title>
<script src="https://cdn.jsdelivr.net/npm/jsonata/jsonata.min.js"></script>
<script src="node_modules/jsonata-extended/dist/jsonata-extended.min.js"></script>
<script>
function runTransform() {
var json = JSON.parse(document.getElementById('json').value);
var transform = document.getElementById('transform').value;
var resultJSONataExtended = jsonataExtended(transform).evaluate(json);
document.getElementById('results').innerHTML = JSON.stringify(resultJSONataExtended);
}
</script>
</head>
<body>
<textarea id="json">{ "name": "Wilbur", "uuid": "11bf5b37-e0b8-42e0-8dcf-dc8c4aefc000" }</textarea>
<textarea id="transform">$.{ "responsename": name, "responseuuid": uuid, "responseshortenUuid" : $shortenUuid ? $shortenUuid(uuid) : "function not defined"}</textarea>
<button onclick="runTransform()">Click me</button>
<p id="results"></p>
</body>
</html>
JSDOCS
License
MIT © Martin Holden