Angular -using jsonPath

2.5k views Asked by At

In my app I want to use json path. I found this library, but I cannot get it to work from my app.

Per the documentation I installed the library and put this line in my component:

import {JSONPath} from 'jsonpath-plus';

But I received an error when I tried to do this:

const blob = JSONPath(path, jsonData, null, null);

Error:

ERROR in ./node_modules/jsonpath-plus/dist/index-es.js
Module not found: Error: Can't resolve 'vm' in 'C:\urm\workspace-1.0.0.2-URM\esploro-web\src\main\ngapp\node_modules\jsonpath-plus\dist'

Any idea how to make it work? Another way to use jsonPath using Angular?

2

There are 2 answers

0
danda On

Apparently there is an open issue about it, still open..

https://github.com/JSONPath-Plus/JSONPath/issues/129

1
Exterminator On

According to the documentation

ESM (Modern browsers) You may also use ES6 Module imports (for modern browsers):

<script type="module">
import {JSONPath} from './node_modules/jsonpath-plus/dist/index-es.js';
const result = JSONPath({path: '...', json: ...});
</script> 

ESM (Bundlers) Or if you are bundling your JavaScript (e.g., with Rollup), just use:

import {JSONPath} from 'jsonpath-plus';
 
const result = JSONPath({path: '...', json});

Try using first one. I guess that will help.