How to use the jsonpath.parse function in jsonpath

To help you get started, we’ve selected a few jsonpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RiseVision / rise-node / src / app.ts View on Github external
.option('-o, --override-config ', 'Override single config item', (opt, opts) => {
    if (typeof(opts) === 'undefined') {
      opts = [];
    }
    const [path, val] = opt.split('=');
    if (typeof(path) === 'undefined' || typeof(val) === 'undefined') {
      // tslint:disable-next-line
      console.warn('Invalid format for invalid config. Correct is -> jsonpath=value');
      return opts;
    }
    try {
      jp.parse(path);
    } catch (e) {
      // tslint:disable-next-line
      console.warn('JSONPath is invalid', e);
    }
    opts.push({ path, val });
    return opts;
  })
  .parse(process.argv);
github RiseVision / rise-node / packages / core-launchpad / src / app.ts View on Github external
(opt, opts) => {
      if (typeof opts === 'undefined') {
        opts = [];
      }
      const [path, val] = opt.split('=');
      if (typeof path === 'undefined' || typeof val === 'undefined') {
        // tslint:disable-next-line
        console.warn(
          'Invalid format for invalid config. Correct is -> jsonpath=value'
        );
        return opts;
      }
      try {
        jp.parse(path);
      } catch (e) {
        // tslint:disable-next-line
        console.warn('JSONPath is invalid', e);
      }
      opts.push({ path, val });
      return opts;
    }
  );
github totherik / step / src / pathutils.js View on Github external
function isDefinitePath(path) {
    if (CACHE.has(path)) {
        return CACHE.get(path);
    }

    const parsed = JSONPath.parse(path);
    const result = !parsed.find(({ expression: { type }, scope }) => {
        // http://goessner.net/articles/JsonPath/
        // https://github.com/jayway/JsonPath#what-is-returned-when
        return INDEFINITE_TYPES.has(type) || INDEFINITE_SCOPES.has(scope);
    });

    CACHE.set(path, result);
    return result;
}
github stoplightio / spectral / src / lint / index.ts View on Github external
public registerRule = (rule: types.LintRule) => {
    if (!rule.severity) {
      rule.severity = this.opts.defaultSeverity;
    }

    try {
      jp.parse(rule.path);
    } catch (e) {
      throw new SyntaxError(`Invalid JSON path for rule '${rule.name}': ${rule.path}\n\n${e}`);
    }

    // update rules object
    this.rules[rule.name] = {
      rule: rule,
      apply: generateRule(rule),
    };

    // update paths object (ensure uniqueness)
    if (!this.paths[rule.path]) {
      this.paths[rule.path] = [];
    }
    let present = false;
    for (const ruleName of this.paths[rule.path]) {
github Azure / autorest / src / autorest-core / language-service / document-analysis.ts View on Github external
public GetJsonQueryAt(position: Position): string | null {
    const lines = this.document.split("\n");
    const potentialQuery: string = (lines[position.line].match(/\B\$[.[].+/g) || [])[0];

    try {
      parse(potentialQuery);
    } catch (e) {
      return null;
    }

    return potentialQuery;
  }
github slurmulon / json-where / src / path.js View on Github external
matches(rel) {
    if (rel && !rel.constructor === String) {
      return false
    }

    try {
      const parsed = jsonPath.parse(rel)

      return !!parsed.length
    } catch (e) {
      return false
    }
  }
github pludov / mobindi / ui / src / shared / JsonPath.ts View on Github external
function parentLoc(jspath:string)
{
    const path = jp.parse(jspath);
    if (path.length < 2) {
        throw new Error("Path has no parent: " + path);
    }
    const last = path[path.length - 1];
    path.splice(path.length - 1, 1);
    checkSimpleSubscript(jspath, last);
    
    return {
        path: path,
        key: last.expression.value
    };
}

jsonpath

Query JavaScript objects with JSONPath expressions. Robust / safe JSONPath engine for Node.js.

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis