Comparing integers from JSON data
See original GitHub issueHello! I’m trying to compare two integers which I’m bringing in as JSON, i.e.:
var template = Template.ParseLiquid("{% if paginator.page != paginator.total_pages %}");
return template.Render(new { paginator = SomeJObject });
However, this yields the following error:
<input>(47,24) : error : Unsupported types `1/Newtonsoft.Json.Linq.JValue` >= `3/Newtonsoft.Json.Linq.JValue` for binary operation
I first thought that this is due to the two integers being JValue
s, not technically int
s, but if I replace one of them in the comparison with a hardcoded integer, it works, and the error does show their respective values (1
and 3
, respectively), so I know Scriban knows what they are. I’d appreciate some guidance on this. Thank you.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to compare integer field with json field?
1 Answer 1 ... This line if(bxqtyy.getText().toString() > minimum_qty.compareTo(BOX_QTY)) is not working because you can't compare string with ...
Read more >What is the correct way to compare jsonPath's value as an ...
Hi, I would like to perform a simple check that verifies that the JSON response contains an integer that is greater than 0....
Read more >Compare Two JSON Objects with Jackson
Learn how to use Jackson to compare two JSON objects using the built-in comparator and a custom comparator.
Read more >nlohmann::basic_json::operator - JSON for Modern C++
Integer and floating-point numbers are automatically converted before comparison. Compares a JSON value and a scalar or a scalar and a JSON value...
Read more >Compare JSON Objects with Jackson
Compare JSON Objects with Custom Comparator ... The JsonNode.equals() method works fine for most of the cases in comparing two objects. However, Jackson...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone else using Json.NET in the future, finding this page through Google, this is what I ended up with:
However, this does not explain the fact that
==
worked earlier. It does fix my problem, though. Yay.I’m not sure whether or not I handled arrays properly with that, so you may have to do some further fiddling about.
Example of some code using
System.Text.Json
to convert to Scriban: