I'd like to use jsonpath to search for items in a flattened JSON. I currently use this maven package:
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>
From an external source I get a flattened json, similar to this (shortened):
"isactive",true
"article","somemoretester"
"name.title","Mr"
"name.first","Corey"
"name.last","Duncan"
"name.name","Mr. Corey Duncan"
"location.street.number",3895
"location.street.name","Mockingbird Ln"
"location.city","Birmingham"
"location.state","Florida"
"location.timezone.offset","0:00"
"location.timezone.description","Western Europe Time, London, Casablanca"
"location.timezone.name","TeaTime"
"location.timezone.prename","NoTea"
"location.details.name","B-City"
"location.details.infratrurcture.publictransport.available",true
"location.details.infratrurcture.publictransport.name","Birmingtrain"
"location.details.infratrurcture.publictransport.lines[0].id","B1"
"location.details.infratrurcture.publictransport.lines[0].name","GreenLine"
"location.details.infratrurcture.publictransport.lines[0].stations",12
"location.details.infratrurcture.publictransport.lines[1].id","B2"
"location.details.infratrurcture.publictransport.lines[1].name","BlueLine"
"location.details.infratrurcture.publictransport.lines[1].stations",5
"location.details.infratrurcture.major.name","Mr. Phil Lazio"
"email","corey.duncan@example.com"
"login.uuid","33768122-74a6-4457-89ec-e5adeb8c179e"
"login.username","tinypeacock919"
"dob.date","1964-07-30T06:19:04.561Z"
"dob.age",57
"dob.name","Birthday"
"nat","US"
"tags[0][0]","name"
"tags[0][1]","nat"
"tags[0][2]","number"
"tags[1][0]","ibu"
"tags[1][1]","infratrurcture"
"tags[1][2]","isactive"
"tags[2][0]","cell"
"tags[2][1]","coordinates"
"tags[2][2]","country"
"tags[3][0]","id"
"tags[3][1]","irrelevant"
"tags[3][2]","infos"
"secrets[0][0][0].name","example1"
"secrets[0][0][0].value","nothing"
"secrets[0][0][1].name","example2"
"secrets[0][0][1].value","same"
"secrets[0][1][0].name","oof"
"secrets[0][1][0].value","ofo"
"secrets[0][1][1].name","java"
"secrets[0][1][1].value","nojava"
"secrets[0][2][0].name","stuff"
"secrets[0][2][0].value","things"
"secrets[0][2][1].name","foo"
"secrets[0][2][1].value","bar"
Is there any way to use this flattened input with the json-path library? I tried something like:
JsonPath.parse(flattenedjson, Configuration.defaultConfiguration()).read("$..name")
But there were no results. If I use an JSON-unflattener and use:
JsonPath.parse(JsonUnflattener.unflatten(flattenedjson), Configuration.defaultConfiguration()).read("$..name")
it'll work like charm...but this unflattening step costs a lot of time. Is there any way to make my first cvode example work?
And as additional question. Is there any way to get a full json as result of the of the read()
Method? Or is the only way to get a 'complete JSON' through call read()
two times (one with Option.AS_PATH_LIST
and one without this option) and merge these two results together to an flot list like above an unflatten it as last step to get a 'normal' JSON?