Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

COSMOS DB Find object within an object based on a value

I have multiple JSON objects within items in COSMOS DB. For example:

"Fruit": {
    "Apples": 200,
    "Oranges": 130,        
    "Strawberries": {
        "Small": 30,
        "Large": "Finished"
    }
    
"Fruit": {
        "Apples": 78,
        "Oranges": 90,        
        "Strawberries": {
            "Small": 10,
            "Large": 30
        }

And I want to return all fruit where large is "Finished". So in this example just the first object would be returned. I imagine this is straightforward to achieve but I haven’t managed to do this. Any help would be great.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A simple where clause would do,

SELECT *
FROM c
WHERE c.Fruit.Strawberries.Large = "Finished"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading