File tree 6 files changed +631
-6
lines changed 6 files changed +631
-6
lines changed Original file line number Diff line number Diff line change 140
140
"js-sha3" : " ^0.9.3" ,
141
141
"jsesc" : " ^3.0.2" ,
142
142
"json5" : " ^2.2.3" ,
143
+ "jsonata" : " ^2.0.3" ,
143
144
"jsonpath-plus" : " ^9.0.0" ,
144
145
"jsonwebtoken" : " 8.5.1" ,
145
146
"jsqr" : " ^1.4.0" ,
Original file line number Diff line number Diff line change 369
369
" Regular expression" ,
370
370
" XPath expression" ,
371
371
" JPath expression" ,
372
+ " Jsonata Query" ,
372
373
" CSS selector" ,
373
374
" Extract EXIF" ,
374
375
" Extract ID3" ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author Jon K ([email protected] )
3
+ * @copyright Crown Copyright 2016
4
+ * @license Apache-2.0
5
+ */
6
+
7
+ import jsonata from "jsonata" ;
8
+ import Operation from "../Operation.mjs" ;
9
+ import OperationError from "../errors/OperationError.mjs" ;
10
+
11
+ /**
12
+ * Jsonata Query operation
13
+ */
14
+ class JsonataQuery extends Operation {
15
+ /**
16
+ * JsonataQuery constructor
17
+ */
18
+ constructor ( ) {
19
+ super ( ) ;
20
+
21
+ this . name = "Jsonata Query" ;
22
+ this . module = "Code" ;
23
+ this . description =
24
+ "Query and transform JSON data with a jsonata query." ;
25
+ this . infoURL = "https://docs.jsonata.org/overview.html" ;
26
+ this . inputType = "string" ;
27
+ this . outputType = "string" ;
28
+ this . args = [
29
+ {
30
+ name : "Query" ,
31
+ type : "text" ,
32
+ value : "string" ,
33
+ } ,
34
+ ] ;
35
+ }
36
+
37
+ /**
38
+ * @param {string } input
39
+ * @param {Object[] } args
40
+ * @returns {string }
41
+ */
42
+ async run ( input , args ) {
43
+ const [ query ] = args ;
44
+ let result , jsonObj ;
45
+
46
+ try {
47
+ jsonObj = JSON . parse ( input ) ;
48
+ } catch ( err ) {
49
+ throw new OperationError ( `Invalid input JSON: ${ err . message } ` ) ;
50
+ }
51
+
52
+ try {
53
+ const expression = jsonata ( query ) ;
54
+ result = await expression . evaluate ( jsonObj ) ;
55
+ } catch ( err ) {
56
+ throw new OperationError (
57
+ `Invalid Jsonata Expression: ${ err . message } `
58
+ ) ;
59
+ }
60
+
61
+ return JSON . stringify ( result === undefined ? "" : result ) ;
62
+ }
63
+ }
64
+
65
+ export default JsonataQuery ;
Original file line number Diff line number Diff line change 11
11
* @license Apache-2.0
12
12
*/
13
13
14
- import {
15
- setLongTestFailure ,
16
- logTestReport ,
17
- } from "../lib/utils.mjs" ;
14
+ import { setLongTestFailure , logTestReport } from "../lib/utils.mjs" ;
18
15
19
16
import TestRegister from "../lib/TestRegister.mjs" ;
20
17
import "./tests/AESKeyWrap.mjs" ;
@@ -89,6 +86,7 @@ import "./tests/IndexOfCoincidence.mjs";
89
86
import "./tests/JA3Fingerprint.mjs" ;
90
87
import "./tests/JA4.mjs" ;
91
88
import "./tests/JA3SFingerprint.mjs" ;
89
+ import "./tests/Jsonata.mjs" ;
92
90
import "./tests/JSONBeautify.mjs" ;
93
91
import "./tests/JSONMinify.mjs" ;
94
92
import "./tests/JSONtoCSV.mjs" ;
@@ -181,14 +179,14 @@ const testStatus = {
181
179
allTestsPassing : true ,
182
180
counts : {
183
181
total : 0 ,
184
- }
182
+ } ,
185
183
} ;
186
184
187
185
setLongTestFailure ( ) ;
188
186
189
187
const logOpsTestReport = logTestReport . bind ( null , testStatus ) ;
190
188
191
- ( async function ( ) {
189
+ ( async function ( ) {
192
190
const results = await TestRegister . runTests ( ) ;
193
191
logOpsTestReport ( results ) ;
194
192
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments