How to use the json-ptr.decodePointer function in json-ptr

To help you get started, we’ve selected a few json-ptr 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 boschni / json-merger / src / operations / MatchOperation.ts View on Github external
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};
        }

        // Process result array item
        const result = this._processor.processArrayItem(keywordValue.value, sourceArray, sourceArrayIndex, resultArray, matchedResultArrayIndex, target);

        // Check if an array item has been inserted or removed below or at the current array item
        if (matchedResultArrayIndex <= resultArrayIndex) {
            resultArrayIndex += result.resultArrayIndex - matchedResultArrayIndex;
        }

json-ptr

A complete implementation of JSON Pointer (RFC 6901) for nodejs and modern browsers.

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis