Skip to content

Equal operator fails for int and double comparisons #123

Description

@kcollister-v
public class JmesPathTest {
    private readonly JObject _objWithDouble = JObject.Parse( """{"fees": [{"fee": 20.0}]}""" );
    private readonly JmesPath _jmesPath = new();

    // No match
    [Fact]
    public async Task FilterByIntegerLiteral_MatchesFloatDataValue() {
        JToken result = await _jmesPath.TransformAsync( _objWithDouble, "fees[?fee==`20`]" );
        Assert.IsType<JArray>( result );
        Assert.Single( (JArray) result );
    }

    // Match
    [Fact]
    public async Task FilterByFloatLiteral_MatchesFloatDataValue() {
        JToken result = await _jmesPath.TransformAsync( _objWithDouble, "fees[?fee==`20.0`]" );
        Assert.IsType<JArray>( result );
        Assert.Single( (JArray) result );
    }
}

Equality filter only matches when type matches (int == int and dbl == dbl, but int != dbl). The above code displays an example of when the filter works as expected and when it does not. The same applies for the reverse (int in array and double in filter). This is not the case for official JMESPath:

Image

The other comparison operators do work (>=, >, etc.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions