2

After several hours of reading and trying all the JSON Path expressions that came into my mind, both logic expressions and non-sense expressions, I still have no idea how I can extract all cmis:objectId where cmis:objectTypeId equals F:cm:custom from ALL object objects no matter the nested depth:

{

    {...   [... nested objects and arrays as needed for a tree strucutre
    object : {
        "succinctProperties": {

            "cmis:objectTypeId": "F:cm:custom",

            "cmis:objectId": "39cdd896-4563-4302-bba9-398006572522",
            ...
        }
    },
    }...   }... close nested objects and arrays as needed for a tree strucutre
    "id": "e244881e-e96b-406b-8d1f-faecae35d7f2"

}

Some things I tried and saved from my hundred attempts:

$.[*]..succinctProperties[?(@['cmis:objectTypeId']=='F:wim:caseEntries')].cmis:objectId


$.[*]..succinctProperties.cmis:objectId // Returns ALL without condition


$.[*].*..succinctProperties[?(@.['cmis:objectTypeId']=='F:wim:caseEntries')]

$.[*]..succinctProperties[@.cmis:objectTypeId=='F:wim:caseEntries')].cmis:objectId

Note: I am using http://www.jsonquerytool.com/ because I use the JMeter Plugin "JSON Path Extractor" and this plugin uses http://goessner.net/articles/JsonPath/

1
  • Nobody who can help me? Please :( Commented Sep 8, 2015 at 14:59

1 Answer 1

6

I am not sure from your question whether you need cmis:objectTypeId to also always be directly under a succinctProperties object or whether it only needs to be somewhere under an object object. If the latter I believe I have a solution to your question. For the former I believe you may have reached the limits of what JSON Path is capable of.

I have used this sample JSON to test the query:

{
    "anotherobject": {
        "object" : {
            "someothernesting": {
                "succinctProperties": {
                    "cmis:objectTypeId": "F:cm:custom",
                    "cmis:objectId": "39cdd896-4563-4302-bba9-398006572522"
                }
            }
        }
    },
    "object" : {
        "succinctProperties": {
            "cmis:objectTypeId": "F:cm:custom",
            "cmis:objectId": "11111111-4563-4302-bba9-222222222222"
        }
    },
    "noobject": {
        "succinctProperties": {
            "cmis:objectTypeId": "F:cm:custom",
            "cmis:objectId": "3333333-4563-4302-bba9-4444444444"
        }
    }
}

This is the query. With $..object.. it looks for all objects anywhere under object objects, and then filters them by only those with a cmis:objectTypeId property:

$..object..[?(@['cmis:objectTypeId']=="F:cm:custom")].cmis:objectId

And these are the results (I also used http://www.jsonquerytool.com to test it):

[
    "11111111-4563-4302-bba9-222222222222",
    "39cdd896-4563-4302-bba9-398006572522"
]

The reason why something like $..succinctProperties[?(@['cmis:objectTypeId']=="F:cm:custom")] returns nothing is because JSON Path generally expects the entity being filtered (in this case succinctProperties) to be an array of objects. The @ refers to an object in the array. Since succinctProperties isn't an array, it treats the object's individual properties as parts of an array and therefore looks for the cmis:objectTypeId property on each property of succinctProperties and not on succinctProperties itself. It would therefore only match something if you had a structure like this:

{
    "succinctProperties": {
        "property": {
            "cmis:objectTypeId": "F:cm:custom",
            "cmis:objectId": "3333333-4563-4302-bba9-4444444444"
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes the cmis:objectId and cmis:objectTypeId are always under a succinctProperties object but the parent-structure varies, sometimes it's $.[*].object.succinctProperties, sometimes it's $.data.[*].object.succinctProperties and sometimes $.[*].object.object.succinctProperties but anyway I now understand how JSONPath hanldes filters differnet on objects and arrays. Thank you very much, I haven't read such infos anywhere so thank you again!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.