Skip to content

Commit 1fbe4f1

Browse files
authored
Switching to JSONPath-Plus (#1)
1 parent 34dfa62 commit 1fbe4f1

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"dependencies": {
2828
"date-fns": "^2.16.1",
29-
"jsonpath": "^1.0.2",
29+
"jsonpath-plus": "^4.0.0",
3030
"memory-cache": "^0.2.0"
3131
}
3232
}

src/DataSource.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22
import { isValid, parseISO } from 'date-fns';
3-
import jp from 'jsonpath';
3+
import { JSONPath } from 'jsonpath-plus';
44

55
import {
66
DataQueryRequest,
@@ -32,10 +32,12 @@ export class DataSource extends DataSourceApi<JsonApiQuery, JsonApiDataSourceOpt
3232
const fields = query.fields
3333
.filter(field => field.jsonPath)
3434
.map(field => {
35-
const values = jp.query(response, field.jsonPath);
35+
const values = JSONPath( { path: field.jsonPath, json: response } );
3636

3737
// Get the path for automatic setting of the field name.
38-
const paths = jp.paths(response, field.jsonPath)[0];
38+
//
39+
// Casted to any due to typing issues with JSONPath-Plus
40+
const paths = (JSONPath as any).toPathArray(field.jsonPath);
3941

4042
const [type, newvals] = detectFieldType(values);
4143

@@ -68,7 +70,7 @@ export class DataSource extends DataSourceApi<JsonApiQuery, JsonApiDataSourceOpt
6870
if (!query.jsonPath) {
6971
return [];
7072
}
71-
return jp.query(await this.api.get(), query.jsonPath).map(_ => ({ text: _ }));
73+
return JSONPath( { path: query.jsonPath, json: await this.api.get() } ).map((_: any) => ({ text: _ }));
7274
}
7375

7476
/**

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7252,6 +7252,11 @@ jsonfile@^4.0.0:
72527252
optionalDependencies:
72537253
graceful-fs "^4.1.6"
72547254

7255+
jsonpath-plus@^4.0.0:
7256+
version "4.0.0"
7257+
resolved "https://registry.yarnpkg.com/jsonpath-plus/-/jsonpath-plus-4.0.0.tgz#954b69faa3d8b07f30ae2f9e601176a4b0d2806e"
7258+
integrity sha512-e0Jtg4KAzDJKKwzbLaUtinCn0RZseWBVRTRGihSpvFlM3wTR7ExSp+PTdeTsDrLNJUe7L7JYJe8mblHX5SCT6A==
7259+
72557260
jsonpath@^1.0.2:
72567261
version "1.0.2"
72577262
resolved "https://registry.yarnpkg.com/jsonpath/-/jsonpath-1.0.2.tgz#e6aae681d03e9a77b4651d5d96eac5fc63b1fd13"

0 commit comments

Comments
 (0)