2

I have a JSON object like this

"office": {
    "parkingRatio": 12.0,
    "hasGenerators": true,
    "generators": [
      {
        "_id": "ff2dc672-6e15-4aa2-afb0-18f4f69596ad",
        "office_id": "b62ce2c1-5fa2-4eee-9ce8-e04a2c3e6513",
        "make": "Broom Broom",
        "covered": true,
        "output": 1234.0
      }
    ]
}

I have a query like this:

$.office.generators[?(@._id =='ff2dc672-6e15-4aa2-afb0-18f4f69596ad')]
$.office.generators[?(@.office_id == 'b62ce2c1-5fa2-4eee-9ce8-e04a2c3e6513')]

If I run this on a few online tools like HERE:

it works fine and gives me the whole array item, but if I run it in json.net v7 it returns nothing.

So i tried the following thinking it might be string

$.office.generators[?(@.covered == true)]

And it works in online tool and json.net. So i tried the following thinking it might be the hyphens

$.office.generators[?(@.make == 'Broom Broom')]

And again it works fine in both. What is wrong with my first query?

Thanks

1 Answer 1

3

Found the problem. The json _id field gets converted into a JValue of type Guid but the expression JValue gets converted into String so when "BooleanQueryExpression" does this comparison

if (v != null && v.Equals(Value))

then its not equal.

I submitted a issue on github

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.