I am traversing a JSON object. Here is my JSON:
{
"type": "Compound",
"body": [
{
"type": "CallExpression",
"arguments": [
{
"type": "CallExpression",
"arguments": [],
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "Identifier",
"name": "Employee"
},
"property": {
"type": "Identifier",
"name": "Name"
}
},
"property": {
"type": "Identifier",
"name": "trim"
}
}
}
],
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "Literal",
"value": "hello",
"raw": "'hello'"
},
"property": {
"type": "Identifier",
"name": "concat"
}
}
},
{
"type": "CallExpression",
"arguments": [],
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "CallExpression",
"arguments": [
{
"type": "Literal",
"value": "Hello",
"raw": "\"Hello\""
}
],
"callee": {
"type": "Identifier",
"name": "and"
}
},
"property": {
"type": "Identifier",
"name": "trim"
}
}
},
{
"type": "Identifier",
"name": "are"
},
{
"type": "CallExpression",
"arguments": [],
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "CallExpression",
"arguments": [
{
"type": "Literal",
"value": "hello",
"raw": "'hello'"
}
],
"callee": {
"type": "Identifier",
"name": "functions"
}
},
"property": {
"type": "Identifier",
"name": "trim"
}
}
},
{
"type": "Identifier",
"name": "for"
},
{
"type": "Identifier",
"name": "expression"
},
{
"type": "CallExpression",
"arguments": [
{
"type": "Identifier",
"name": "fg1"
}
],
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "CallExpression",
"arguments": [
{
"type": "Literal",
"value": "Hello",
"raw": "'Hello'"
}
],
"callee": {
"type": "CallExpression",
"arguments": [],
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "CallExpression",
"arguments": [
{
"type": "Literal",
"value": "Hello",
"raw": "'Hello'"
}
],
"callee": {
"type": "CallExpression",
"arguments": [
{
"type": "Literal",
"value": "hello",
"raw": "'hello'"
}
],
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "CallExpression",
"arguments": [
{
"type": "Literal",
"value": "Hello",
"raw": "'Hello'"
}
],
"callee": {
"type": "CallExpression",
"arguments": [],
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "CallExpression",
"arguments": [
{
"type": "Literal",
"value": "Hello",
"raw": "'Hello'"
}
],
"callee": {
"type": "CallExpression",
"arguments": [],
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "CallExpression",
"arguments": [
{
"type": "Literal",
"value": "Hello",
"raw": "'Hello'"
}
],
"callee": {
"type": "Identifier",
"name": "builder"
}
},
"property": {
"type": "Identifier",
"name": "trim"
}
}
}
},
"property": {
"type": "Identifier",
"name": "length"
}
}
}
},
"property": {
"type": "Identifier",
"name": "concat"
}
}
}
},
"property": {
"type": "Identifier",
"name": "length"
}
}
}
},
"property": {
"type": "Identifier",
"name": "length"
}
}
}
]
}
I am looking for all callee from body object whose "type"="CallExpression"
. For the parsing I am using the JSPath library.
For this, I have code as
var collee= JSPath.apply('.body.callee',parse_tree,{ "type":"CallExpression"})
But it is throwing an error cache[path] is not a function, maybe because the return value is of type object?