Getting keys and values from a list on a JSON String using BasicDBObject
Date : March 29 2020, 07:55 AM
wish of those help I have a String with a JSON that contains a list. Its something like this: Document document = Document.parse(jsonString);
List<Document> countsArray = document.get("counts",List.class);
for (Document doc : countsArray){
doc.keySet(); //keys
doc.values(); //values
for (Map.Entry entry : doc.entrySet()){
// iterate over each pair
}
}
|
How to convert 2 Java String arrays of keys & values into a json object
Tag : java , By : alexmajy
Date : March 29 2020, 07:55 AM
I hope this helps you . You can iterate over the arrays, taking each key, value pair, and add them to a JSON object. gson: JsonObject jsonObject = new JsonObject();
for (int i = 0; i < keys.length; i ++) {
jsonObject.addProperty(keys[i], values[i]);
}
ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
for (int i = 0; i < keys.length; i ++) {
jsonObject.put(keys[i], values[i]);
}
|
How to convert a Json tree of string keys and float values to a Map
Date : March 29 2020, 07:55 AM
I hope this helps you . I have the below String and I wanted to convert it into a Map of String, Float. , Try this: Map<String, Float> map = mapper.readValue(tree, new TypeReference<Map<String, Float>>(){});
|
search and replace values for multiple keys in a json string using pcre regex for a list of keys
Tag : regex , By : Milander
Date : March 29 2020, 07:55 AM
I wish this helpful for you Use: Find: (?:^.*?\| PRE2 \|.*?{\K|\G)(.*?"(?:key1|key2|key4)":")\w+("[,}]) Replace: $1_x_$2
|
Is there a direct way to convert Map<String, List<String>> into a JSON String (using javax.json library)
Tag : java , By : Tom Berthon
Date : March 29 2020, 07:55 AM
|