-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathembedding-extending.html
185 lines (174 loc) · 24.3 KB
/
embedding-extending.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>Embedding and Extending JSONata · JSONata</title><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta name="generator" content="Docusaurus"/><meta name="description" content="## API"/><meta name="docsearch:version" content="2.0.0"/><meta name="docsearch:language" content="en"/><meta property="og:title" content="Embedding and Extending JSONata · JSONata"/><meta property="og:type" content="website"/><meta property="og:url" content="http://docs.jsonata.org/"/><meta property="og:description" content="## API"/><meta name="twitter:card" content="summary"/><link rel="shortcut icon" href="/img/jsonata-button.png"/><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/><script type="text/javascript" src="https://buttons.github.io/buttons.js"></script><script type="text/javascript" src="/js/jsonata-examples.js"></script><script src="/js/scrollSpy.js"></script><link rel="stylesheet" href="/css/main.css"/><script src="/js/codetabs.js"></script></head><body class="sideNavVisible separateOnPageNav"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/"><img class="logo" src="/img/jsonata-button.png" alt="JSONata"/><h2 class="headerTitleWithLogo">JSONata</h2></a><a href="/versions"><h3>2.0.0</h3></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li class="siteNavGroupActive"><a href="/overview" target="_self">Docs</a></li><li class=""><a href="http://try.jsonata.org" target="_self">Try</a></li><li class=""><a href="https://github.com/jsonata-js/jsonata" target="_self">GitHub</a></li><li class=""><a href="https://www.npmjs.com/package/jsonata" target="_self">NPM</a></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="docsNavContainer" id="docsNav"><nav class="toc"><div class="toggleNav"><section class="navWrapper wrapper"><div class="navBreadcrumb wrapper"><div class="navToggle" id="navToggler"><div class="hamburger-menu"><div class="line1"></div><div class="line2"></div><div class="line3"></div></div></div><h2><i>›</i><span>Extending JSONata</span></h2><div class="tocToggler" id="tocToggler"><i class="icon-toc"></i></div></div><div class="navGroups"><div class="navGroup"><h3 class="navGroupCategoryTitle">Getting Started</h3><ul class=""><li class="navListItem"><a class="navItem" href="/overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/using-nodejs">In NodeJS</a></li><li class="navListItem"><a class="navItem" href="/using-browser">In a Web Page</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Language Guide</h3><ul class=""><li class="navListItem"><a class="navItem" href="/simple">Simple Queries</a></li><li class="navListItem"><a class="navItem" href="/predicate">Predicate Queries</a></li><li class="navListItem"><a class="navItem" href="/expressions">Functions and Expressions</a></li><li class="navListItem"><a class="navItem" href="/construction">Result Structures</a></li><li class="navListItem"><a class="navItem" href="/composition">Query Composition</a></li><li class="navListItem"><a class="navItem" href="/sorting-grouping">Sorting, Grouping and Aggregation</a></li><li class="navListItem"><a class="navItem" href="/processing">Processing Model</a></li><li class="navListItem"><a class="navItem" href="/programming">Functional Programming</a></li><li class="navListItem"><a class="navItem" href="/regex">Regular Expressions</a></li><li class="navListItem"><a class="navItem" href="/date-time">Date/Time Processing</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Operators</h3><ul class=""><li class="navListItem"><a class="navItem" href="/path-operators">Path Operators</a></li><li class="navListItem"><a class="navItem" href="/numeric-operators">Numeric Operators</a></li><li class="navListItem"><a class="navItem" href="/comparison-operators">Comparison Operators</a></li><li class="navListItem"><a class="navItem" href="/boolean-operators">Boolean Operators</a></li><li class="navListItem"><a class="navItem" href="/other-operators">Other Operators</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Function Library</h3><ul class=""><li class="navListItem"><a class="navItem" href="/string-functions">String Functions</a></li><li class="navListItem"><a class="navItem" href="/numeric-functions">Numeric Functions</a></li><li class="navListItem"><a class="navItem" href="/aggregation-functions">Aggregation Functions</a></li><li class="navListItem"><a class="navItem" href="/boolean-functions">Boolean Functions</a></li><li class="navListItem"><a class="navItem" href="/array-functions">Array Functions</a></li><li class="navListItem"><a class="navItem" href="/object-functions">Object Functions</a></li><li class="navListItem"><a class="navItem" href="/date-time-functions">Date/Time Functions</a></li><li class="navListItem"><a class="navItem" href="/higher-order-functions">Higher Order Functions</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Extending JSONata</h3><ul class=""><li class="navListItem navListItemActive"><a class="navItem" href="/embedding-extending">Embedding and Extending JSONata</a></li><li class="navListItem"><a class="navItem" href="/contributing">Community and Contributing</a></li></ul></div></div></section></div><script>
var coll = document.getElementsByClassName('collapsible');
var checkActiveCategory = true;
for (var i = 0; i < coll.length; i++) {
var links = coll[i].nextElementSibling.getElementsByTagName('*');
if (checkActiveCategory){
for (var j = 0; j < links.length; j++) {
if (links[j].classList.contains('navListItemActive')){
coll[i].nextElementSibling.classList.toggle('hide');
coll[i].childNodes[1].classList.toggle('rotate');
checkActiveCategory = false;
break;
}
}
}
coll[i].addEventListener('click', function() {
var arrow = this.childNodes[1];
arrow.classList.toggle('rotate');
var content = this.nextElementSibling;
content.classList.toggle('hide');
});
}
document.addEventListener('DOMContentLoaded', function() {
createToggler('#navToggler', '#docsNav', 'docsSliderActive');
createToggler('#tocToggler', 'body', 'tocActive');
var headings = document.querySelector('.toc-headings');
headings && headings.addEventListener('click', function(event) {
var el = event.target;
while(el !== headings){
if (el.tagName === 'A') {
document.body.classList.remove('tocActive');
break;
} else{
el = el.parentNode;
}
}
}, false);
function createToggler(togglerSelector, targetSelector, className) {
var toggler = document.querySelector(togglerSelector);
var target = document.querySelector(targetSelector);
if (!toggler) {
return;
}
toggler.onclick = function(event) {
event.preventDefault();
target.classList.toggle(className);
};
}
});
</script></nav></div><div class="container mainContainer docsContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/jsonata-js/jsonata/edit/master/docs/embedding-extending.md" target="_blank" rel="noreferrer noopener">Edit</a><h1 id="__docusaurus" class="postHeaderTitle">Embedding and Extending JSONata</h1></header><article><div><span><h2><a class="anchor" aria-hidden="true" id="api"></a><a href="#api" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>API</h2>
<h3><a class="anchor" aria-hidden="true" id="jsonatastr"></a><a href="#jsonatastr" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>jsonata(str)</h3>
<p>Parse a string <code>str</code> as a JSONata expression and return a compiled JSONata expression object.</p>
<pre><code class="hljs css language-javascript"><span class="hljs-keyword">var</span> expression = jsonata(<span class="hljs-string">"$sum(example.value)"</span>);
</code></pre>
<p>If the expression is not valid JSONata, an <code>Error</code> is thrown containing information about the nature of the syntax error, for example:</p>
<pre><code class="hljs">{
<span class="hljs-symbol"> code:</span> <span class="hljs-string">"S0202"</span>,
<span class="hljs-symbol"> stack:</span> <span class="hljs-string">"..."</span>,
<span class="hljs-symbol"> position:</span> <span class="hljs-number">16</span>,
<span class="hljs-symbol"> token:</span> <span class="hljs-string">"}"</span>,
<span class="hljs-symbol"> value:</span> <span class="hljs-string">"]"</span>,
<span class="hljs-symbol"> message:</span> <span class="hljs-string">"Syntax error: expected ']' got '}'"</span>
}
</code></pre>
<p><code>expression</code> has three methods:</p>
<h3><a class="anchor" aria-hidden="true" id="expressionevaluateinput-bindings-callback"></a><a href="#expressionevaluateinput-bindings-callback" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>expression.evaluate(input[, bindings[, callback]])</h3>
<p>Run the compiled JSONata expression against object <code>input</code> and return the result as a new object.</p>
<pre><code class="hljs css language-javascript"><span class="hljs-keyword">var</span> result = <span class="hljs-keyword">await</span> expression.evaluate({<span class="hljs-attr">example</span>: [{<span class="hljs-attr">value</span>: <span class="hljs-number">4</span>}, {<span class="hljs-attr">value</span>: <span class="hljs-number">7</span>}, {<span class="hljs-attr">value</span>: <span class="hljs-number">13</span>}]});
</code></pre>
<p><code>input</code> should be a JavaScript value such as would be returned from <code>JSON.parse()</code>. If <code>input</code> could not have been parsed from a JSON string (is circular, contains functions, ...), <code>evaluate</code>'s behaviour is not defined. <code>result</code> is a new JavaScript value suitable for <code>JSON.stringify()</code>ing.</p>
<p><code>bindings</code>, if present, contains variable names and values (including functions) to be bound:</p>
<pre><code class="hljs css language-javascript"><span class="hljs-keyword">await</span> jsonata(<span class="hljs-string">"$a + $b()"</span>).evaluate({}, {<span class="hljs-attr">a</span>: <span class="hljs-number">4</span>, <span class="hljs-attr">b</span>: <span class="hljs-function"><span class="hljs-params">()</span> =></span> <span class="hljs-number">78</span>});
<span class="hljs-comment">// returns 82</span>
</code></pre>
<p><code>expression.evaluate()</code> may throw a run-time <code>Error</code>:</p>
<pre><code class="hljs css language-javascript"><span class="hljs-keyword">var</span> expression = jsonata(<span class="hljs-string">"$notafunction()"</span>); <span class="hljs-comment">// OK, valid JSONata</span>
<span class="hljs-keyword">await</span> expression.evaluate({}); <span class="hljs-comment">// Throws</span>
</code></pre>
<p>The <code>Error</code> contains information about the nature of the run-time error, for example:</p>
<pre><code class="hljs">{
<span class="hljs-symbol"> code:</span> <span class="hljs-string">"T1006"</span>,
<span class="hljs-symbol"> stack:</span> <span class="hljs-string">"..."</span>,
<span class="hljs-symbol"> position:</span> <span class="hljs-number">14</span>,
<span class="hljs-symbol"> token:</span> <span class="hljs-string">"notafunction"</span>,
<span class="hljs-symbol"> message:</span> <span class="hljs-string">"Attempted to invoke a non-function"</span>
}
</code></pre>
<p>If <code>callback(err, value)</code> is supplied, <code>expression.evaluate()</code> returns <code>undefined</code>, the expression is run asynchronously and the <code>Error</code> or result is passed to <code>callback</code>.</p>
<pre><code class="hljs css language-javascript"><span class="hljs-keyword">await</span> jsonata(<span class="hljs-string">"7 + 12"</span>).evaluate({}, {}, (error, result) => {
<span class="hljs-keyword">if</span>(error) {
<span class="hljs-built_in">console</span>.error(error);
<span class="hljs-keyword">return</span>;
}
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Finished with"</span>, result);
});
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Started"</span>);
<span class="hljs-comment">// Prints "Started", then "Finished with 19"</span>
</code></pre>
<h3><a class="anchor" aria-hidden="true" id="expressionassignname-value"></a><a href="#expressionassignname-value" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>expression.assign(name, value)</h3>
<p>Permanently binds a value to a name in the expression, similar to how <code>bindings</code> worked above. Modifies <code>expression</code> in place and returns <code>undefined</code>. Useful in a JSONata expression factory.</p>
<pre><code class="hljs css language-javascript"><span class="hljs-keyword">var</span> expression = jsonata(<span class="hljs-string">"$a + $b()"</span>);
expression.assign(<span class="hljs-string">"a"</span>, <span class="hljs-number">4</span>);
expression.assign(<span class="hljs-string">"b"</span>, () => <span class="hljs-number">1</span>);
<span class="hljs-keyword">await</span> expression.evaluate({}); <span class="hljs-comment">// 5</span>
</code></pre>
<p>Note that the <code>bindings</code> argument in the <code>expression.evaluate()</code> call clobbers these values:</p>
<pre><code class="hljs css language-javascript"><span class="hljs-keyword">await</span> expression.evaluate({}, {<span class="hljs-attr">a</span>: <span class="hljs-number">109</span>}); <span class="hljs-comment">// 110</span>
</code></pre>
<h3><a class="anchor" aria-hidden="true" id="expressionregisterfunctionname-implementation-signature"></a><a href="#expressionregisterfunctionname-implementation-signature" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>expression.registerFunction(name, implementation[, signature])</h3>
<p>Permanently binds a function to a name in the expression.</p>
<pre><code class="hljs css language-javascript"><span class="hljs-keyword">var</span> expression = jsonata(<span class="hljs-string">"$greet()"</span>);
expression.registerFunction(<span class="hljs-string">"greet"</span>, () => <span class="hljs-string">"Hello world"</span>);
<span class="hljs-keyword">await</span> expression.evaluate({}); <span class="hljs-comment">// "Hello world"</span>
</code></pre>
<p>You can do this using <code>expression.assign</code> or <code>bindings</code> in <code>expression.evaluate</code>, but <code>expression.registerFunction</code> allows you to specify a function <code>signature</code>. This is a terse string which tells JSONata the expected input argument types and return value type of the function. JSONata raises a run-time error if the actual input argument types do not match (the return value type is not checked yet).</p>
<pre><code class="hljs css language-javascript"><span class="hljs-keyword">var</span> expression = jsonata(<span class="hljs-string">"$add(61, 10005)"</span>);
expression.registerFunction(<span class="hljs-string">"add"</span>, (a, b) => a + b, <span class="hljs-string">"<nn:n>"</span>);
<span class="hljs-keyword">await</span> expression.evaluate({}); <span class="hljs-comment">// 10066</span>
</code></pre>
<h3><a class="anchor" aria-hidden="true" id="function-signature-syntax"></a><a href="#function-signature-syntax" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Function signature syntax</h3>
<p>A function signature is a string of the form <code><params:return></code>. <code>params</code> is a sequence of type symbols, each one representing an input argument's type. <code>return</code> is a single type symbol representing the return value type.</p>
<p>Type symbols work as follows:</p>
<p>Simple types:</p>
<ul>
<li><code>b</code> - Boolean</li>
<li><code>n</code> - number</li>
<li><code>s</code> - string</li>
<li><code>l</code> - <code>null</code></li>
</ul>
<p>Complex types:</p>
<ul>
<li><code>a</code> - array</li>
<li><code>o</code> - object</li>
<li><code>f</code> - function</li>
</ul>
<p>Union types:</p>
<ul>
<li><code>(sao)</code> - string, array or object</li>
<li><code>(o)</code> - same as <code>o</code></li>
<li><code>u</code> - equivalent to <code>(bnsl)</code> i.e. Boolean, number, string or <code>null</code></li>
<li><code>j</code> - any JSON type. Equivalent to <code>(bnsloa)</code> i.e. Boolean, number, string, <code>null</code>, object or array, but not function</li>
<li><code>x</code> - any type. Equivalent to <code>(bnsloaf)</code></li>
</ul>
<p>Parametrised types:</p>
<ul>
<li><code>a<s></code> - array of strings</li>
<li><code>a<x></code> - array of values of any type</li>
</ul>
<p>Some examples of signatures of built-in JSONata functions:</p>
<ul>
<li><code>$count</code> has signature <code><a:n></code>; it accepts an array and returns a number.</li>
<li><code>$append</code> has signature <code><aa:a></code>; it accepts two arrays and returns an array.</li>
<li><code>$sum</code> has signature <code><a<n>:n></code>; it accepts an array of numbers and returns a number.</li>
<li><code>$reduce</code> has signature <code><fa<j>:j></code>; it accepts a reducer function <code>f</code> and an <code>a<j></code> (array of JSON objects) and returns a JSON object.</li>
</ul>
<p>Each type symbol may also have <em>options</em> applied.</p>
<ul>
<li><code>+</code> - one or more arguments of this type
<ul>
<li>E.g. <code>$zip</code> has signature <code><a+></code>; it accepts one array, or two arrays, or three arrays, or...</li>
</ul></li>
<li><code>?</code> - optional argument
<ul>
<li>E.g. <code>$join</code> has signature <code><a<s>s?:s></code>; it accepts an array of strings and an optional joiner string which defaults to the empty string. It returns a string.</li>
</ul></li>
<li><code>-</code> - if this argument is missing, use the context value ("focus").
<ul>
<li>E.g. <code>$length</code> has signature <code><s-:n></code>; it can be called as <code>$length(OrderID)</code> (one argument) but equivalently as <code>OrderID.$length()</code>.</li>
</ul></li>
</ul>
<h3><a class="anchor" aria-hidden="true" id="writing-higher-order-function-extensions"></a><a href="#writing-higher-order-function-extensions" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Writing higher-order function extensions</h3>
<p>It is possible to write and extension function that takes one or more functions in its list of arguments and/or returns
a function as its return value.</p>
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/higher-order-functions"><span class="arrow-prev">← </span><span>Higher Order Functions</span></a><a class="docs-next button" href="/contributing"><span>Community and Contributing</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#api">API</a><ul class="toc-headings"><li><a href="#jsonatastr">jsonata(str)</a></li><li><a href="#expressionevaluateinput-bindings-callback">expression.evaluate(input[, bindings[, callback]])</a></li><li><a href="#expressionassignname-value">expression.assign(name, value)</a></li><li><a href="#expressionregisterfunctionname-implementation-signature">expression.registerFunction(name, implementation[, signature])</a></li><li><a href="#function-signature-syntax">Function signature syntax</a></li><li><a href="#writing-higher-order-function-extensions">Writing higher-order function extensions</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/jsonata-white-167.png" alt="JSONata"/></a><div><h5>JSONata</h5><a href="http://jsonata.org" target="_blank" rel="noreferrer noopener">JSON query and<br/>transformation language</a><a href="http://try.jsonata.org" target="_blank" rel="noreferrer noopener">Go play in the<br/>JSONata Exerciser</a></div><div><h5>Community</h5><a href="https://stackoverflow.com/questions/tagged/jsonata" target="_blank" rel="noreferrer noopener">Stack Overflow</a><a href="https://jsonata.slack.com/">Project Chat</a><a href="https://twitter.com/" target="_blank" rel="noreferrer noopener">Twitter</a></div><div><h5>More</h5><a href="https://github.com/jsonata-js/jsonata">GitHub</a><a class="github-button" href="https://github.com/jsonata-js/jsonata" data-icon="octicon-star" data-count-href="/jsonata-js/jsonata/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2021 JSONata.org</section></footer></div></body></html>