Topic
  • No replies
Aparna_Aravind
Aparna_Aravind
7 Posts

Pinned topic How to write a jaql query

‏2013-06-03T09:34:56Z |

Can someone please help me to write the jaql query to count the number of ocurances of "TEAM:INDIA" in tag1 in the following JSON objects?

The file contains JSON objects of the following formats (JSON1 and JSON2).  i.e some obj may start with interact while some others start with demo(both within same file).

I am able to find the count when all start with interact but not when both are present.

JSON1:

{
"interact": {
"tag1": [
"TEAM:INIDA",
"CRITERIA:Hashtag"
]
},
"tag2": {
"topics": [
"science and technology",
"moms",
"some values",
"movies",
"mib3"
]
},
"twitter": {
"mentions": [
"somethg"
],
"source": "somethg",
"text": "something",
"user": {
"description": "something"
}
}
}

 

JSON2:
{
"demo": {
"gender": "male"
},
"interaction": {
"content": "somthing",
"id": "somthg",
"link": "somthg",
"schema": {
"version": 3
},
"source": "somthg",
"type": "somthg",
"tag1": [
"TEAM: INDIA",
"CRITERIA: Hashtag"
]
},
"language": {
"confidence": 64,
"tag": "en"
},
"salience": {
"content": {
"sentiment": 0,
"topics": [
{
"name": "somthg",
"score": 0.46243894100189,
"hits": 0
}
]
}
},
"twitter": {
"mentions": [
"somthing"
],
"source": "somthing",
"text": "something",
"user": {
"utc_offset": -18000
}
}
}

 

 

I used the following query:

b=for( $b in read(file("/path/to/file.json")) )
if( 'TEAM:INDIA' in $b.interaction.tags[*] )
[{$b.interaction.tags }];
b->group into count($);