How to use the jsonpath.paths 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 magda-io / magda / magda-web-client / src / Components / Dataset / Add / ValidationManager.ts View on Github external
function findItemsByJsonPath(jsonPath: string): ValidationItem[] {
    if (!jsonPath) {
        return [];
    }
    const item = findItemByExactJsonPathMatch(jsonPath);
    if (typeof item !== "undefined") {
        // --- we will stop if we find an exact matched item
        return [item];
    }

    const items: ValidationItem[] = [];

    const stateData = getStateData();
    JsonPath.paths(stateData, jsonPath)
        .map(item => JsonPath.stringify(item))
        .forEach(resolvedJsonPath => {
            const item = findItemByExactJsonPathMatch(resolvedJsonPath);
            if (typeof item !== "undefined") {
                items.push(item);
            }
        });
    return items;
}
github boschni / json-merger / src / operations / MatchOperation.ts View on Github external
processInArray(keyword: string, source: any, sourceArray: any[], sourceArrayIndex: number, resultArray: any[], resultArrayIndex: number, target: any[]) {
        const keywordValue: MatchKeywordValue = source[keyword];

        let matchedResultArrayIndex: number;

        // Handle $match.index
        if (keywordValue.index !== undefined) {
            matchedResultArrayIndex = keywordValue.index === "-" ? resultArray.length - 1 : keywordValue.index;
        }

        // Handle $match.query
        else if (keywordValue.query !== undefined) {
            // Try to find a matching item in the result
            const path = jsonpath.paths(resultArray, keywordValue.query)[0];
            matchedResultArrayIndex = path !== undefined ? path[1] as number : undefined;
        }

        // Handle $match.path
        else if (keywordValue.path !== undefined) {
            // Try to find a matching item in the result
            if (jsonPtr.get(resultArray, keywordValue.path) !== undefined) {
                [matchedResultArrayIndex] = jsonPtr.decodePointer(keywordValue.path)[0];
            }
        }

        // Ignore the item if no match found
        if (matchedResultArrayIndex === undefined || resultArray[matchedResultArrayIndex] === undefined) {
            return {resultArray, resultArrayIndex};
        }
github benjamin-allion / json-node-normalizer / lib / core / schema.js View on Github external
const getFieldPaths = (schema, config = defaultConfig) => {
  const typeFieldName = config.fieldNames.type; // 'type' by default
  let paths = jp.paths(schema, `$..[?(@.${typeFieldName} && @.${typeFieldName}!="object")]`);

  // Array path ['$','properties','field'] to jsonPath '$.properties.field'
  paths = paths.map(path => jp.stringify(path));
  // Remove 'definitions' fields
  paths = paths.filter(path => !path.includes('.definitions.'));

  logger.debug(`Paths that must be normalized ${JSON.stringify(paths)}`);
  return paths;
};
github Azure / autorest / src / autorest-core / language-service / document-analysis.ts View on Github external
public * GetDocumentLocations(jsonQuery: string): Iterable {
    for (const path of paths(this.fullyResolvedAndMergedDefinition, jsonQuery)) {
      for (const mappingItem of this.fullyResolvedAndMergedDefinitionMap.LookupPath(path.slice(1))) {
        yield {
          uri: mappingItem.source,
          range: {
            start: {
              line: mappingItem.originalLine - 1, // VS Code deviates from the source map standard here... 0 vs. 1 based line numbers
              character: mappingItem.originalColumn
            },
            end: {
              line: mappingItem.originalLine - 1,
              character: mappingItem.originalColumn // TODO: room for improvement. think there even is extended information in `name`!
            }
          }
        };
      }
    }
github mmendesas / walnutjs / src / support / parser / jsonparser.js View on Github external
deleteKey: function (path) {
        const parent = jp.parent(this.jsonObj, path);
        const paths = jp.paths(this.jsonObj, path);
        const item = paths[0].pop();

        if (Array.isArray(parent)) {
            parent.splice(item, 1);
        } else {
            delete parent[item];
        }
    }
}
github magda-io / magda / magda-web-client / src / Components / Dataset / Add / ValidationManager.ts View on Github external
const idx = validationFieldList.findIndex(fieldPath => {
        if (
            JsonPath.paths(stateData, fieldPath)
                .map(item => JsonPath.stringify(item))
                .indexOf(jsonPath) !== -1
        ) {
            return true;
        } else {
            return false;
        }
    });
    if (idx !== -1) {
github Talend / ui / packages / cmf / scripts / cmf-settings.i18n.js View on Github external
function parseSettings(i18next, settings, locale) {
	const clonedSettings = cloneDeep(settings);
	i18next.changeLanguage(locale);
	jsonpath
		.paths(clonedSettings, JSON_PATH_EXPRESSION)
		.forEach(jsonpaths => setTranslate(i18next, clonedSettings, jsonpaths));

	return clonedSettings;
}
github sdawood / json-tots / src / extension / policy / collapse_snake_case.js View on Github external
module.exports = (parent, child, tagPath, document) => {
    const tagPathLeaf = jp.paths(document, jpify(tagPath)).pop().pop();
    return _.snakeCase([parent, child, tagPathLeaf]);
};
github box / box-openapi / src / swaggerConverter.js View on Github external
simplifyQueryItems(object) {
    const paths = jp.paths(object, `$..items`)
    paths.forEach(path => {
      path.pop()
      jp.apply(object, jp.stringify(path), (value) => {
        if (value.in === 'query') {
          value.items = { type: 'string' }
        }
        return 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