I'm having some trouble trying query a JSON with Java JsonPath.
I have a large json with informations about people location (thousand of lines). The field to find the person location is your macAdreess. The macAdreess does not repeat, in other words when I query for a specific macAdreess, I got once result.
This is a small piece of my Json:
{
"readings": [
{
"value": {
"floorRefId": "-4564288095083560912",
"x": 86.405304,
"y": 64.4601,
"z": 0
},
"tags": {
"macAddress": "f8:e0:79:82:95:92"
},
"timestamp": 1494620148598
},
{
"value": {
"floorRefId": "-4564288095083560912",
"x": 86.540474,
"y": 64.12458,
"z": 0
},
"tags": {
"macAddress": "f4:f5:24:96:d5:cd"
},
"timestamp": 1494620148598
},
{
"value": {
"floorRefId": "-4564288095083560912",
"x": 86.31584,
"y": 64.410446,
"z": 0
},
"tags": {
"macAddress": "f4:f5:24:2a:9c:13"
},
"timestamp": 1494620148598
},
],
"gateway_uuid": "cccccccc-9f70-4d93-94be-2fa7e15ef292",
"status": "running"
}
I will need to query for one macAddress into JSON every five seconds, so if I need to traverse all JSON content, I will have a performance trouble.
Then I'm trying to use Java JsonPath API to query the macAdreess and it's running ok. But I need to get the parent node to get the location fields.
With this code:
public static void main(String[] args) throws Exception {
String json = getJsonAsString();
List<Map<String, Object>> expensive = JsonPath.parse(json).read("$..[?(@.macAddress=='f4:f5:24:96:d5:cd')]");
System.out.println(expensive);
}
I got thit result:
[{"macAddress":"f4:f5:24:96:d5:cd"}]