JSON Query Language is designed to translate JSON into Linq easily and introduce more concepts of Linq in JSON Query.

Format

Query => '{' ( ('Field[:Operator]' | $or | $not | $and ) : ['Value'|Query] ) * '}'

Field

Field holds name of the field that corresponds to name of field of object in Entity Framework.

Operator

Operator is optional, default is considered as '==' , but it can be any of following.

!= Does not Equal
<= Less or Equal
>= Greater or Equal
< Less
> Greater
StartsWith Applicable on String, StartsWith Method
EndsWith Applicable on String, EndsWith Method
Contains Applicable on String, Contains Method
DoesNotStartsWith Applicable on String, NOT (StartsWith Method)
DoesNotEndsWith Applicable on String, NOT (EndsWith Method)
DoesNotContains Applicable on String, NOT (Contains Method)
In Contains in given Array
Any When field is a plural navigation property, Any is applicable to test condition on navigation property. Value in this case will be nested JSON Object Query.

$or

By default, fields of JSON object query are combined with BOOLEAN AND operator. If field contains $or then children of $or query are combined with OR operator.

$and

By default, fields of JSON object query are combined with BOOLEAN AND operator. Inside $or operator construct, if you want to combine nested conditions with AND then you can use $and operator.

$not

Using $not as field will cause, Boolean NOT to be applied on to the nested Query.

Examples

Following examples will give you idea of how to use above operators

Equals Operator

    { 'AccountID': 2 }
  x => x.AccountID == 2

Not Equals Operator

    { 'AccountID:!=' : 2 }
    x => x.AccountID != 2

Not Operator

    { '$not' : {  'AccountID' : 2 } }
    x => !( x.AccountID == 2 )

Default And Operator

    {  'AccountName:Contains': 'Akash', 'AccountType':'Admin'  }
    x => ( x.AccountName.Contains("Akash") ) && ( x.AccountType == "Admin" )

OR Operator

    { '$or' : {  'AccountName:Contains': 'Akash', 'AccountType':'Admin'  } }
    x => ( x.AccountName.Contains("Akash") ) || ( x.AccountType == "Admin" )

Any

    { 'OrderStatus' : 'Complete' , 'OrderItems:Any' : {  } }
    x => x.OrderStatus == "Complete" && x.OrderItems.Any()

Any With Nested Condition

    { 'OrderStatus' : 'Complete' , 'OrderItems:Any' : {  'ItemID': 224 } }
    x => x.OrderStatus == "Complete" && x.OrderItems.Any( y => y.ItemID == 224 )

Last edited May 28, 2013 at 6:52 PM by neurospeech, version 6

Comments

No comments yet.