Creating an OJAI Query Condition Using a JSON String

You can create a query condition using OJAI syntax to specify the condition in JSON format. This is the preferred approach for the Node.js, Python, C#, and Go OJAI clients.

The following example shows you how to create the following query condition using the syntax:

(a.b.[0].boolean == false && (a.c.d != 5 || a.b[1].decimal > 1 || a.b[1].decimal < 10))

This is a Java string for the condition:

String jc = new String(
    '{ \
        "$and":[ \
            {"$eq":{"a.b[0].boolean":false}}, \
            {"$or":[ \
                {"$ne":{"a.c.d":5}}, \
                {"$gt":{"a.b[1].decimal":1}}, \
                {"$lt":{"a.b[1].decimal":10}} \
            ]} \
        ]} \
    )';

Pass the string to the Query.where method. See the Java - OJAI Query Condition in JSON Format example at Querying with Conditions for a complete Java code example.

This is a Node.js JSON object for the condition:

query = 
    {"$where":
        {"$and":[ 
            {"$eq":{"a.b[0].boolean":false}}, 
            {"$or":[                 
                {"$ne":{"a.c.d":5}}, 
                {"$gt":{"a.b[1].decimal":1}}, 
                {"$lt":{"a.b[1].decimal":10}} 
            ]}
        ]}
    };

See the Node.js - OJAI Query Condition in JSON Format example at Querying with Conditions for a complete Node.js code example.

This is a Python dictionary for the condition:

query = 
    {"$where":
        {"$and":[ 
            {"$eq":{"a.b[0].boolean":false}}, 
            {"$or":[                 
                {"$ne":{"a.c.d":5}}, 
                {"$gt":{"a.b[1].decimal":1}}, 
                {"$lt":{"a.b[1].decimal":10}} 
            ]}
        ]}
    } 

See the Python - OJAI Query Condition in JSON Format example at Querying with Conditions for a complete Python code example.

This is a JSON string for the condition:

var query =
    @"{""$where"":" +
        @"{""$and"":[" +
            @"{""$eq"":{""a.b[0].boolean"":false}}," + 
            @"{""$or"":[" +                 
                @"{""$ne"":{""a.c.d"":{""$numberInt"":""5""}}}," +
                @"{""$gt"":{""a.b[1].decimal"":{""$decimal"":""1""}}}," +
                @"{""$lt"":{""a.b[1].decimal"":{""$decimal"":""10""}}}" +
            @"]}" +
        @"]" +
   @"}";

This is a JSON string for the condition:

query := "{\"$where\": +
               "{\"$and\":[" +
                      "{\"$eq\":{\"a.b[0].boolean\":false}}," +
                      "{\"$or\":[" +
                            "{\"$ne\":{\"a.c.d\":5}}," +
                            "{\"$gt\":{\"a.b[1].decimal\":1}}," +
                            "{\"$lt\":{\"a.b[1].decimal\":10}}" +
                      "]}" +
               "]}" +
          "}"

To learn about the complete OJAI syntax for query conditions, see OJAI Query Condition Syntax.

Note: The OJAI clients are supported starting in MEP 6.0.0.