0

I want to get the value against "name" field from the below json. I tried using the tools http://jsonpathfinder.com/ and http://jsonpath.com/? I am using http://jsonpath.herokuapp.com/ to verify if the expression path is correct, but it always returns me as an incorrect expression.

{
  "data" : {
    "PensionRetriever(Customer=ABC, typeInfo=valid)" : {
      "name" : "lifeInsurance",
      "created_at" : 1552297775384,
      "attributes" : [ {
        "id" : "4044da39-c23b-4588-b6c4-975ce02e7cb2",
        "name" : "lifeInsurance",
        "created_at" : 1552297775384
   }]
    }
  }
}

I tried with $.data["PensionRetriever(Customer=ABC, typeInfo=valid)"].name , but this seems incorrect. Can you please tell me now to get the value of "name" , i.e., lifeInsurance

RoyalTiger
  • 511
  • 2
  • 8
  • 27
  • What do you mean with `incorrect` when you call `$.data["PensionRetriever(Customer=ABC, typeInfo=valid)"].name`? And what is returned when you call `console.log($.data)`? – tomrlh Mar 11 '19 at 11:44
  • It's giving me "Found empty property at index 55" – RoyalTiger Mar 11 '19 at 18:55

2 Answers2

1

Use single quoted rather than double quoted names in the JSONPath expression, i.e.

$.data['PensionRetriever(Customer=ABC, typeInfo=valid)'].name

Using the online evaluators on http://jsonpath.herokuapp.com/, the usually reliable Jayway fails, apparently unable to digest the name 'PensionRetriever(Customer=ABC, typeInfo=valid)'. That's a Jayway bug. But Goessner succeeds, returning the expected

[    "lifeInsurance" ]
Daniel
  • 728
  • 7
  • 11
-1

var path = $.JSONPath({data: json, keepHistory: false}); var test=path.query('$.data.PensionRetriever(Customer=ABC,typeInfo=valid).name');

song bo
  • 16
  • 1