How to use the jsonpath-plus.eval function in jsonpath-plus

To help you get started, we’ve selected a few jsonpath-plus 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 facebook / facebook-business-sdk-codegen / src / processors / SpecOverridingProcessor.js View on Github external
process(specs, metadata) {
    const language: string = metadata.language || '';
    const flags = metadata.mergedOverriding.flags;
    let APISpecs = specs.api_specs;
    const languageDef = codeGenLanguages[language];
    const specOverriding = metadata.mergedOverriding.spec_overriding;
    for (const clsName in specOverriding) {
      for (const jsonPath in specOverriding[clsName]) {
        const value = specOverriding[clsName][jsonPath];
        const $ = APISpecs[clsName] || {};
        const evalPathes =
          jsonPath === '$'
            ? ['$']
            : JSONPath.eval($, jsonPath, {resultType: 'path'});
        if (evalPathes.length === 0) {
          throw new Error(
            'MUST_FIX: cannot find JSON path need to be patched.\n' +
              clsName +
              '::' +
              jsonPath,
          );
        }

        if (value === null) {
          // Delete
          evalPathes.forEach((path: string) => {
            // Find the parent path before it
            // Since all paths are of the form $[..][..][..] we only need
            // to remove the last [..]
            const lastBracketPos = path.lastIndexOf('[');

jsonpath-plus

A JS implementation of JSONPath with some additional operators

MIT
Latest version published 9 hours ago

Package Health Score

67 / 100
Full package analysis