Here is the json string from which i have to retrieve the element value
{ "search": { "entry": [
{ "d": "op=example.com",
"at": [
{ "name": "id", "value": [ "786786876" ] },
{ "name": "name", "value": [ "usaduas" ] }]
},
{ "d": "op=example.com",
"at": [
{ "name": "id", "value": [ "786876876" ] },
{ "name": "call", "value": [ "gyudyusg" ] }]
},
{ "d": "op=example.com",
"at": [
{ "name": "call", "value": [ "hsadkjhsakjdh" ] },
{ "name": "id", "value": [ "768768768" ] }]
}
I want to retrieve the text from attribute or node "name" : "call". I want to retrieve this value using jsonPath.
Thanks in advance.
please try one of these as per your understanding. These two are most convenient and highly used API to Serialize or Deserialize the JSONObject google gson API tutorial-convert-java-object-to-from-json
OR
Google Json simple API example-read-and-write-json
Related
I've a document of type:
{...
"array1": [
{
"id": "id1",
"value": "v1"
},
{
"id": "id2",
"value": "v2"
}
],
"array2": [
{
"id": "id-1",
"value": "value1"
},
{
"id": "id-2",
"value": "value2"
}
]
}
to get only the value that matches my conditions from the array1 and array2 in js we can do this,
db.mydb.find({...},{ _id: 0, "array1" : {$elemMatch: {"id" :"id1"}},"array2" : {$elemMatch: {"id" :"id-2"}}})
but I wonder how to do the same thing in Spring boot
my expected answer :
{
"array1": [
{
"id": "id1",
"value": "v1"
}
],
"array2": [
{
"id": "id-2",
"value": "value2"
}
]
}
I want to get some idea if there is any library in Java that I can use to filter a JSON document based on a predefined JSON mapping document, or only way to achieve this is to write custom java code.
If it's required to write Java custom code what type of design pattern or data structure I should follow. Any advice will be very much appreciated.
Example -
Input JSON document -
{
"basicInfo": {
"name": "name",
"age": "25",
"address": "address"
},
"education": [
{
"ug": {
"unversity": "university",
"major": [
"cs",
"ds"
],
"year": "2012"
},
"pg": {
"unversity": "university",
"major": [
"cs",
"ds"
],
"year": "2015"
}
}
]
}
Predefined JSON mapping document (Can be defined in any JSON format, below is one such example that I have created) -
{
"definitions": {
"basicInfo": {
"maxOccurance": "1",
"fields": [
{
"key": "name",
"type": "S",
"lenght": "50",
"usage": "M",
"maxOccurrance": "1"
},
{
"key": "age",
"type": "S",
"lenght": "3",
"usage": "O",
"maxOccurrance": "1"
}
]
},
"education": {
"maxOccurance": "10",
"fields": [
{
"pg": {
"maxOccurance": "1",
"fields": [
{
"key": "university",
"type": "S",
"lenght": "50",
"usage": "M",
"maxOccurrance": "1"
},
{
"key": "major",
"type": "S",
"lenght": "3",
"usage": "O",
"maxOccurrance": "1"
}
]
}
}
]
}
}
}
Expected output JSON document
{
"basicInfo": {
"name": "name",
"age": "25"
},
"education": [
{
"pg": {
"unversity": "university",
"major": "cs"
}
}
]
}
The request is for a way to filter a JSON document based on a predefined JSON spec sheet / JSON mapping document. The jolt library would likely be able to meet this requirement.
I have to send request body as org.hl7.fhir.r4.model.CoverageEligibilityRequest which is contained Patient, Practitioner, Organization as below. This API will return Bundle response. I am using Java and Generic client from Hapi Fire library. There is provision to pass search parameter but the here I am having multilevel hierarchy of resource and input is big than usual. Can any one help me to handle this request in FHIR API.
Request Body as below,
{
"resourceType": "CoverageEligibilityRequest",
"contained": [
{
"resourceType": "Patient",
"id": "1",
"name": [
{
"family": "abcFamily",
"given": [
"abcGiven"
]
}
],
"birthDate": "1962-08-06"
},
{
"resourceType": "Practitioner",
"id": "2",
"identifier": [
{
"type": {
"coding": [
{
"code": "NPI"
}
]
},
"value": "123456789"
}
],
"name": [
{
"family": "pqrFamily",
"given": [
"pqrGiven"
]
}
]
},
{
"resourceType": "Organization",
"id": "3",
"identifier": [
{
"value": "12345"
}
],
"name": ""
},
{
"resourceType": "Coverage",
"id": "3",
"status": "active",
"subscriberId": "",
"class": [
{
"type": {
"coding": [
{
"code": "group"
}
]
},
"value": ""
}
]
}
],
"extension": [
{
"url": "searchOption",
"valueString": "NameDateOfBirth"
}
],
"status": "active",
"purpose": [
"benefits"
],
"patient": {
"reference": "#1"
},
"provider": {
"reference": "#2"
},
"insurer": {
"reference": "#3"
}
}
I have the following json which get from endpoint,
{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:response",
"urn:scim:schemas:extension:customattrs:2.0:User"
],
"meta": {
"resourceType": "User",
"created": "2011-08-01T18:29:49.793Z",
"lastModified": "2011-08-01T18:29:49.793Z",
"version": "W/\"f250dd84f0671c3\""
},
"userName": "bjensen",
"phoneNumbers": [
{
"value": "555-555-8377",
"type": "work"
}
],
"emails": [
{
"value": "bjensen#example.com",
"type": "work",
"primary": true
}
],
"urn:scim:schemas:extension:customattrs:2.0:User": {
"userName": "bjensen",
"address": ""
}
}
please suggest me to parse the json along with schemas "urn:scim:schemas:extension:customattrs:2.0:User" into java object
I have the following table in cassandra. (row level data)
The last column(ENGINE_CC) is unique. I want to categories the available data with respect to that column.
Required output in form of nested json:
{
"VECHILE_TYPE": [
{
"name": "Two Wheeler",
"MODEL": [
{
"name": "Bike",
"SUBMODEL": [
{
"name": "Super Bike",
"VECHILE_NAME": [
{
"name": "Suzuki_Hayabusa",
"Engine_CC": [
"250",
"300",
"450"
]
},
{
"name": "GSX",
"Engine_CC": [
"225",
"200"
]
}
]
},
{
"name": "Street Bike",
"VECHILE_NAME": [
{
"name": "Gixxer",
"Engine_CC": [
"175",
"150"
]
}
]
}
]
}
]
},
{
"name": "Four Wheeler",
"MODEL": [
{
"name": "Economic",
"SUBMODEL": [
{
"name": "Hatchback",
"VECHILE_NAME": [
{
"name": "I10",
"Engine_CC": [
"1000",
"1200"
]
},
{
"name": "Santro",
"Engine_CC": [
"800",
"900"
]
}
]
}
]
}
]
}
]
}
Could someone suggest
1)JAVA model for the nested json
2)How to add the row level data to the model
Is any library available to achieve this. This is basically a design question. Any suggestions ? Thanks in advance.