Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 13 hours ago.
Improve this question
I have a List<List<String>> data like this
[
[
"DATABASE_NAME",
"CURRENT_MEMORY_SIZE",
"MAX_MEMORY_SIZE"
],
[
"bbb",
"10",
"10"
],
[
"aaa",
"20",
"20"
] ]
How can I convert this list to an object like this?
[
[
"DATABASE_NAME": "bbb",
"CURRENT_MEMORY_SIZE": "10",
"MAX_MEMORY_SIZE":"10"
],
[
"MAX_MEMORY_SIZE":"aaa",
"MAX_MEMORY_SIZE":"20",
"MAX_MEMORY_SIZE":"20"
] ]
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 days ago.
Improve this question
i have list of dynamic object in java as below,
{country='Japan', rate=81 },
{country='Brazil', rate=76 },
{country='China', rate=75 },
{country='Colombia', rate=69},
{country='South Korea', rate=54 },
{country='EU trade marks', rate=46 }
having some filter criteria like from 50 to 70 rating or selected country [Brazil,China] either or
i want a custom sort mechanism either java 8 or comparator etc,
so that i can get sorted array like below, if only criteria is from 50 to 70 rating,then higher rate is topmost form the filter criteria and rest are below in descending order.
{country='Colombia', rate=69},
{country='South Korea', rate=54 },
{country='Japan', rate=81 },
{country='Brazil', rate=76 },
{country='China', rate=75 },
{country='EU trade marks', rate=46 }
if criteria is set for selected country [Brazil,China] then no matters the rate, selected country are first with alphabetic order, then from higher to lower rate one.
{country='Brazil', rate=76 },
{country='China', rate=75 },
{country='Japan', rate=81 },
{country='Colombia', rate=69},
{country='South Korea', rate=54 },
{country='EU trade marks', rate=46 }
I am working with the Jayway JsonPath library to obtain the correct 'id' from below JSON where my phoneNumbers type is 'iPhone'.
In general, I would like to know how to find something from the root element of a block when a specific condition is specified in the sub-JSON objects.
I tried below expressions that select the block associated with iPhone type and also a list of ids respectively, but I am not able to get to the root element id belonging to the JSON object where my phone type is iPhone. Can someone please guide me? I need to get the id as 1 for this question.
To get the list of ids: $[*].id
To get the json object corresponding to iPhone type: $[*].phoneNumbers[?(#.type=='iPhone')]
[
{
"id": "1",
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567-8888"
},
{
"type": "home",
"number": "0123-4567-8910"
}
]
},
{
"id": "2",
"phoneNumbers": [
{
"type": "x",
"number": "0123-4567-8888"
},
{
"type": "y",
"number": "0123-4567-8910"
}
]
}
]
I think you want your expression to look deeper.
First, find the objects that have an iPhone in the phone numbers list. Then just select the IDs.
Try $[?(#.phoneNumbers[*].type=="iPhone")].id.
Edit
It looks like the Java JsonPath library (I think you're using this) supports a number of functions. It doesn't list a contains(), but you might try the anyof operator:
$[?(#.phoneNumbers[*].type anyof ["iPhone"])].id
Note that this is definitely implementation-specific and will likely not work with any other library.
let's say I have a String which has a format as Json.
If I want to separate values from the String.
and exchange the values with '#number'.
Currently, I don't know the keys.
Is there any easy way to get this result?
for example,
from
{
"data": [
{
"skills": "Java",
"platforms": "Web"
}
],
"status": "100"
}
to
{
"data": [
{
"skills": #1,
"platforms": #2
}
],
"status": #3
}
with array result [Java, Web, 100]
Probably if you are looking to parse a unknown json and print the values Check this out
I wont be able to give you the exact code you need, but you should be able to implement on similar lines
My json:
{
"activities": [
{
"type": "post",
"id": "160",
"name": "John Wayne",
"content": "this is the actual post",
"timestamp" : "date + time",
},
{
"type": "post"
"id": "161",
"name": "Angelina Jolie",
"content": "this is the actual post",
"timestamp" : "date + time",
{
"type": "comment"
"id": "162",
"name": "Ravi Tamada",
"content": "content of the comment",
"timestamp" : "time + date",
"secondary_id": "160"
}
]
}
I have 2 types of objects which i have to consider: comment and post.
Every comment is linked to a post with its secondary id. That means if secondary_id is "160" this comment belongs to the the post with the id 160. In my json there could be 50 posts then 1 comment to the 2nd post follwed by 10 more psots and then 6 various comments. Means its not orderd.
So now im trying to figure out how to safe them in my java code to get them linked. Means i need every comment for a certain post. I could do 2 arrays 1 for posts 1 for comments and then search the comments array for every comment with the id 160...161..etc... this would be pretty messy i guess.
Isnt there some pattern or smth like the key is 160 and now give me all the secondary id´s mapped as value for that key or smth?
I hope you know what i mean, kinda of hard to expain.
Basically what i would need is smth like go through the json check if its post if yes safe it. If its a comment look up the secondary id and match it to the map(or smth) of the right primary id.
First of all when serializing JSON in java there are libraries you can use, Jackson for example.
Once you familiar yourself with Jackson, I would create a base class for comment and post that has all the fields that are shared by them.
I would create a custom deserializer that after creating a comment object looking up the post object and adding the comment to the post.
My situation is this:
I have an index that has been generated by an entirely different app and I want to transplant/expose it from solr.
I can easily do that, but the problem now is I can't query on any of the fields. I just get empty {}
I modified the schema to include the fields from the documents transplanted and it doesn't seem to have made a difference.
When I do a q=*:* I can see all the documents so I know the info is there. This has to be easy. I am just missing it.
Would anyone like to give me an education?
Document example:
"docs": [
{
"code": "A000",
"description": "Cholera due to Vibrio cholerae 01, biovar cholerae",
"version": "10",
"concepts": [
"cholera",
"cholera-due to biovar cholera",
"cholera-due to vibrio cholerae 01",
"infectious diseases",
"intestinal infectious diseases"
],
"tags": [
"biovar",
"cholera",
"cholerae",
"diseases",
"infectious",
"intestinal",
"vibrio"
],
"category": "A00",
"etiology": "0"
},
]