JmesPath.Net
JmesPath.Net copied to clipboard
Doesn't properly parse for max_by
Given the following JSON:
Sample JSON array
{
"matches": [
{
"comp_level": 5,
"winning_alliance": 0,
"key": "2024alhu_f1m1",
"set_number": 1,
"match_number": 1,
"alliances": {
"red": {
"score": 120,
"team_keys": [
"frc5002",
"frc4635",
"frc2481"
],
"surrogate_team_keys": [],
"dq_team_keys": []
},
"blue": {
"score": 60,
"team_keys": [
"frc7111",
"frc4265",
"frc6517"
],
"surrogate_team_keys": [],
"dq_team_keys": []
}
},
"event_key": "2024alhu",
"time": 1712436840,
"actual_time": 1712438011,
"predicted_time": 1712438103,
"post_result_time": 1712438219,
"score_breakdown": {
"ValueKind": 1
},
"videos": [
{
"type": "youtube",
"key": "K3Jv2DdIN1A"
}
]
},
{
"comp_level": 5,
"winning_alliance": 0,
"key": "2024alhu_f1m2",
"set_number": 1,
"match_number": 2,
"alliances": {
"red": {
"score": 94,
"team_keys": [
"frc5002",
"frc4635",
"frc2481"
],
"surrogate_team_keys": [],
"dq_team_keys": []
},
"blue": {
"score": 80,
"team_keys": [
"frc7111",
"frc4265",
"frc6517"
],
"surrogate_team_keys": [],
"dq_team_keys": []
}
},
"event_key": "2024alhu",
"time": 1712438100,
"actual_time": 1712439464,
"predicted_time": 1712439426,
"post_result_time": 1712439684,
"score_breakdown": {
"ValueKind": 1
},
"videos": [
{
"type": "youtube",
"key": "ESV5X7EAmAQ"
}
]
},
{
"winning_alliance": 0,
"key": "2024alhu_qm1",
"set_number": 1,
"match_number": 1,
"alliances": {
"red": {
"score": 68,
"team_keys": [
"frc1466",
"frc9590",
"frc4020"
],
"surrogate_team_keys": [],
"dq_team_keys": []
},
"blue": {
"score": 35,
"team_keys": [
"frc5410",
"frc7717",
"frc6107"
],
"surrogate_team_keys": [],
"dq_team_keys": []
}
},
"event_key": "2024alhu",
"time": 1712325300,
"actual_time": 1712325230,
"predicted_time": 1712325300,
"post_result_time": 1712325429,
"score_breakdown": {
"ValueKind": 1
},
"videos": [
{
"type": "youtube",
"key": "gZe4iPmNwIw"
}
]
}
]
}
The JMESPath expression max_by(matches, &alliances.red.score) should return the single record:
{
"comp_level": 5,
"winning_alliance": 0,
"key": "2024alhu_f1m1",
"set_number": 1,
"match_number": 1,
"alliances": {
"red": {
"score": 120,
"team_keys": [
"frc5002",
"frc4635",
"frc2481"
],
"surrogate_team_keys": [],
"dq_team_keys": []
},
"blue": {
"score": 60,
"team_keys": [
"frc7111",
"frc4265",
"frc6517"
],
"surrogate_team_keys": [],
"dq_team_keys": []
}
},
"event_key": "2024alhu",
"time": 1712436840,
"actual_time": 1712438011,
"predicted_time": 1712438103,
"post_result_time": 1712438219,
"score_breakdown": {
"ValueKind": 1
},
"videos": [
{
"type": "youtube",
"key": "K3Jv2DdIN1A"
}
]
}
According to the tester on JMESPath.org.
However, when applied via JmesPath.Net, and exception is thrown:
System.Exception
HResult=0x80131500
Message=Error: invalid-type, the expression argument of function max_by should return a number or a string.
Source=JmesPath.Net
StackTrace:
at DevLab.JmesPath.Functions.ByFunction.<EvaluateAsync>d__3.MoveNext()
at DevLab.JmesPath.Functions.MaxByFunction.<ExecuteAsync>d__2.MoveNext()
at DevLab.JmesPath.Expressions.JmesPathFunctionExpression.<TransformAsync>d__10.MoveNext()
at DevLab.JmesPath.Expressions.JmesPathExpression.<TransformAsync>d__1.MoveNext()
at DevLab.JmesPath.Expressions.JmesPathRootExpression.<TransformAsync>d__6.MoveNext()
at DevLab.JmesPath.Expressions.JmesPathExpression.<TransformAsync>d__1.MoveNext()
This exception was originally thrown at this call stack:
DevLab.JmesPath.Functions.ByFunction.EvaluateAsync(DevLab.JmesPath.Expressions.JmesPathExpression, Newtonsoft.Json.Linq.JToken)
DevLab.JmesPath.Functions.MaxByFunction.ExecuteAsync(DevLab.JmesPath.Functions.JmesPathFunctionArgument[])
DevLab.JmesPath.Expressions.JmesPathFunctionExpression.TransformAsync(Newtonsoft.Json.Linq.JToken)
DevLab.JmesPath.Expressions.JmesPathExpression.TransformAsync(DevLab.JmesPath.Expressions.JmesPathArgument)
DevLab.JmesPath.Expressions.JmesPathRootExpression.TransformAsync(Newtonsoft.Json.Linq.JToken)
DevLab.JmesPath.Expressions.JmesPathExpression.TransformAsync(DevLab.JmesPath.Expressions.JmesPathArgument)
@bc3tech thanks for your feedback.
What version of JmesPath.NET are you using? I unfortunately, cannot reproduce your issue.
Can you clarify what you tried ? Do you have a minimal repro case ?