34

I have the following JSON Store on Azure Cosmos DB.

{
  "id": "4",
  "total": 10.46,
  "tax": 0.55,
  "soldItems": [
    {
      "item": "CHEESE NIPS 004400001300 F 1.97 D",
      "price": 1.97
    },
    {
      "item": "ROOT BEER 10.46",
      "price": 10.46
    }
    ]
}

and I am getting no results from this query:

SELECT * from c where CONTAINS(c.soldItems.item, "BEER")

What would be the correct syntax to check for a string in an JSON object value?

amy8374
  • 1,450
  • 3
  • 17
  • 26

1 Answers1

65

Try this:

SELECT VALUE c FROM c JOIN s in c.soldItems WHERE CONTAINS(s.item, "BEER")
Larry Maccherone
  • 9,393
  • 3
  • 27
  • 43