Skip to content

Conversation

ashphy
Copy link
Owner

@ashphy ashphy commented Mar 16, 2025

Close #6

Added a feature to retrieve the normalized path defined at RFC9535 2.7

Usage

Add a path function

import { JSONPathJS } from "jsonpath-js";

const query = new JSONPathJS("$.users[*].name");
const result = query.paths({
	users: [{ name: "John Doe" }, { name: "Jane Doe" }],
});

// [
// 	{ value: "John Doe", path: "$['users'][0]['name']" },
// 	{ value: "Jane Doe", path: "$['users'][1]['name']" },
// ];
console.log(result);

@ashphy ashphy self-assigned this Mar 17, 2025
@ashphy ashphy added the enhancement New feature or request label Mar 17, 2025
@ashphy ashphy force-pushed the ashphy/issue6 branch 2 times, most recently from 88a0f82 to a19d3d4 Compare March 18, 2025 13:55
@ashphy ashphy marked this pull request as ready for review March 18, 2025 14:41
@ashphy ashphy requested a review from Copilot March 18, 2025 14:41
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces a normalized path feature as defined in RFC9535 2.7, enabling retrieval of normalized paths from JSONPath queries. Key changes include:

  • Implementation of a new escapeMemberName function for correctly escaping member names.
  • Updates to node creation, traversal, and filtering functions to support normalized paths.
  • Expanded test coverage and documentation updates to illustrate the new paths() functionality.

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/utils/escapeMemberName.ts Introduces a new function to escape member names per RFC9535 for normalized paths.
src/utils/enumarateNode.ts Adds a function to enumerate nodes using the new normalized node structure.
src/types/node.ts Updates node definitions and helper functions for normalized paths.
README.md Updates the usage documentation with examples of the new paths() function.
tests/utils.ts Adds tests verifying the normalized path output.
tests/RFC9535/jsonpath-compliance-test-suite.test.ts Adds additional tests covering normalized path outputs.
src/parsers/root.ts, traverseDescendant.ts, jsonpath_js.ts, parser.ts, etc. Adjust existing functions to work with the updated Node structure and support normalized paths.
src/functions/, src/parsers/, src/comparator/* Refactors and adjusts implementations to correctly extract node values and normalized paths.
tests/index.test.ts, tests/RFC9535/ietf_jsonpath.test.ts Updates tests to reflect modifications in node structure and function outputs.

@ashphy ashphy merged commit aa5561b into main Mar 19, 2025
7 checks passed
@ashphy ashphy deleted the ashphy/issue6 branch March 19, 2025 13:22
@loilo loilo mentioned this pull request Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Having a way to get a path instead of just the result would be great
1 participant