Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use fully functioning JsonPath in angular 2+?

I followed https://www.npmjs.com/package/jsonpath. Tried a way to include external js file, but no luck.

like image 733
Veshraj Joshi Avatar asked Sep 19 '25 22:09

Veshraj Joshi


1 Answers

import jsonPath worked after -

import * as jsonPath from 'jsonpath/jsonpath';

JsonPath plush also worked JSONPath-plus which is same as of Jsonpath. I have following coding snippet which is working for me-

install JSONPath-plus

npm install jsonpath-plus

angular.json file

"scripts": [
    "node_modules/jsonpath-plus/dist/index-umd.js",
    "src/assets/js/jsonpath.js"
]

jsonpath.js have following code -

function jsonPath() {
  return JSONPath;
}

Now use this function in ts file with declaring it like below -

declare const jsonPath: any;
// use it like
 jsonPath().JSONPath(path, json);

 
like image 170
Veshraj Joshi Avatar answered Sep 23 '25 10:09

Veshraj Joshi