Skip to content

Commit

Permalink
Merge pull request #842 from json-everything/path/improved-nodelist-f…
Browse files Browse the repository at this point in the history
…unctions

Path/improved nodelist functions
  • Loading branch information
gregsdennis authored Dec 27, 2024
2 parents fd35401 + 0bb7648 commit 378bbc6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
35 changes: 34 additions & 1 deletion src/JsonPath.Tests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class NoOpFunction : NodelistFunctionDefinition
{
return nodeList;
}

}

[Test]
Expand Down Expand Up @@ -80,4 +79,38 @@ public void ExpressionWithNoOpFunctionWorks()

JsonAssert.AreEquivalent(expected, actual);
}

[Test]
public void ExpressionWithNestedNoOpFunctionWorks()
{
FunctionRepository.RegisterNodelistFunction<NoOpFunction>();

// should do the same thing as $[?@.*]
var path = JsonPath.Parse("$[?noop(noop(noop(@.*)))]");
var data = JsonNode.Parse(
"""
[
{"foo": 9},
{"foo": 18, "bar": false},
{},
42,
["yes", "no", 0],
true,
null
]
""");

var expected = JsonNode.Parse(
"""
[
{"foo": 9},
{"foo": 18, "bar": false},
["yes", "no", 0]
]
""");

var actual = path.Evaluate(data).Matches.Select(x => x.Value).ToJsonArray();

JsonAssert.AreEquivalent(expected, actual);
}
}
4 changes: 2 additions & 2 deletions src/JsonPath/Expressions/FunctionValueExpressionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ public bool TryParse(ReadOnlySpan<char> source, ref int index, int nestLevel, [N
return false;
}

if (function is not ValueFunctionDefinition valueFunction)
if (function is LogicalFunctionDefinition)
{
expression = null;
return false;
}

index = i;
expression = new FunctionValueExpressionNode(valueFunction, parameters);
expression = new FunctionValueExpressionNode(function, parameters);
return true;
}
}
4 changes: 2 additions & 2 deletions src/JsonPath/JsonPath.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageId>JsonPath.Net</PackageId>
<Version>2.0.0</Version>
<FileVersion>2.0.0</FileVersion>
<Version>2.0.1</Version>
<FileVersion>2.0.1</FileVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Authors>Greg Dennis</Authors>
<Description>JSON Path (RFC 9535) built on the System.Text.Json namespace</Description>
Expand Down
8 changes: 6 additions & 2 deletions tools/ApiDocsGenerator/release-notes/rn-json-path.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ title: JsonPath.Net
icon: fas fa-tag
order: "09.08"
---
# [2.0.1](https://github.com/gregsdennis/json-everything/pull/842) {#release-path-2.0.1}

[#837](https://github.com/gregsdennis/json-everything/pull/837) - Support for nested nodelist functions. Thanks to [@He-Pin](https://github.com/He-Pin) for reporting and fixing this.

# [2.0.0](https://github.com/gregsdennis/json-everything/pull/822) {#release-path-2.0.0}

- Add .Net 9.0 support.
Expand All @@ -12,11 +16,11 @@ order: "09.08"

# [1.1.6](https://github.com/gregsdennis/json-everything/pull/797) {#release-path-1.1.6}

[#797](https://github.com/gregsdennis/json-everything/pull/797) - ``.TryParse()`` does not respect `PathParsingOptions.AllowRelativeStart`. Thanks to [@mikechristiansenvae](https://github.com/mikechristiansenvae) for reporting and fixing this.
[#797](https://github.com/gregsdennis/json-everything/pull/797) - `.TryParse()` does not respect `PathParsingOptions.AllowRelativeStart`. Thanks to [@mikechristiansenvae](https://github.com/mikechristiansenvae) for reporting and fixing this.

# [1.1.5](https://github.com/gregsdennis/json-everything/pull/788) {#release-path-1.1.5}

[#787](https://github.com/gregsdennis/json-everything/issues/787) - ``.TryParse()`` would throw when encountering a `.`-selector at the end of the string. Thanks to [@Nexiimil](https://github.com/Nexiimil) for reporting this.
[#787](https://github.com/gregsdennis/json-everything/issues/787) - `.TryParse()` would throw when encountering a `.`-selector at the end of the string. Thanks to [@Nexiimil](https://github.com/Nexiimil) for reporting this.

# [1.1.4](https://github.com/gregsdennis/json-everything/pull/775) {#release-path-1.1.4}

Expand Down

0 comments on commit 378bbc6

Please sign in to comment.