How to conditionally return specific value with another in JSONPath?

I've got an object like this one:

{
    "content": {
        "iteration_size": 1
    }
}

I need a JSONPath which returns null if the value of next_item is exactly 1, or the value of iteration_size otherwise. So the above should return null and "iteration_size": 2 should return 2. Is this possible in JSONPath?

I've tried variations on $.content[?(@.iteration_size == 1)].iteration_size, but the two online evaluators I've tried even disagree on the results of several of my attempts.

The use case is the AWS Batch API, where the array size must be either null or a number between 2 and 10,000.



Read more here: https://stackoverflow.com/questions/66235519/how-to-conditionally-return-specific-value-with-another-in-jsonpath

Content Attribution

This content was originally published by l0b0 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: