use of net.minidev.json.JSONArray in project molgenis by molgenis.
the class RestControllerV2IT method batchCreateLocation.
@Test
public void batchCreateLocation() {
JSONObject jsonObject = new JSONObject();
JSONArray entities = new JSONArray();
JSONObject entity = new JSONObject();
entity.put("Chromosome", "42");
entity.put("Position", 42);
entities.add(entity);
jsonObject.put("entities", entities);
String expectedLocation = "/api/v2/it_emx_datatypes_Locationv2?q=Position=in=(\"42\")";
String expectedHref = "/api/v2/it_emx_datatypes_Locationv2/42";
given().log().all().header(X_MOLGENIS_TOKEN, testUserToken).contentType(APPLICATION_JSON).body(jsonObject.toJSONString()).when().post(API_V2 + "it_emx_datatypes_Locationv2").then().statusCode(RestTestUtils.CREATED).log().all().body("location", Matchers.equalTo(expectedLocation), "resources[0].href", Matchers.equalTo(expectedHref));
}
use of net.minidev.json.JSONArray in project JsonPath by jayway.
the class Issue273 method testGetPropertyFromObject.
@Test
public void testGetPropertyFromObject() {
String json = "{\n" + " \"store\": {\n" + " \"book\": [\n" + " {\n" + " \"category\": \"reference\",\n" + " \"author\": \"Nigel Rees\",\n" + " \"title\": \"Sayings of the Century\",\n" + " \"price\": 8.95\n" + " },\n" + " {\n" + " \"category\": \"fiction\",\n" + " \"author\": \"Evelyn Waugh\",\n" + " \"title\": \"Sword of Honour\",\n" + " \"price\": 12.99\n" + " },\n" + " {\n" + " \"category\": \"fiction\",\n" + " \"author\": \"Herman Melville\",\n" + " \"title\": \"Moby Dick\",\n" + " \"isbn\": \"0-553-21311-3\",\n" + " \"price\": 8.99\n" + " },\n" + " {\n" + " \"category\": \"fiction\",\n" + " \"author\": \"J. R. R. Tolkien\",\n" + " \"title\": \"The Lord of the Rings\",\n" + " \"isbn\": \"0-395-19395-8\",\n" + " \"price\": 22.99\n" + " }\n" + " ],\n" + " \"bicycle\": {\n" + " \"color\": \"red\",\n" + " \"price\": 19.95\n" + " }\n" + " },\n" + " \"expensive\": 10\n" + "}\n" + " ";
JSONArray arr = JsonPath.read(json, "$..[2].author");
assertEquals(arr.get(0), "Herman Melville");
}
use of net.minidev.json.JSONArray in project skype-bot by toomasr.
the class BitBucketHookHandler method handle.
@Override
public Map<String, String[]> handle(Map<String, String[]> parameters, String requestBody) {
try {
requestBody = URLDecoder.decode(requestBody, "UTF-8");
requestBody = requestBody.replaceFirst("payload=", "");
JSONObject object = (JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(requestBody);
JSONObject repo = (JSONObject) object.get("repository");
// String repoName = (String) repo.get("name");
String absoluteUrl = (String) repo.get("absolute_url");
String repoUrl = "https://bitbucket.org" + absoluteUrl;
List<String> messages = new ArrayList<String>();
JSONArray commits = (JSONArray) object.get("commits");
for (int i = 0; i < commits.size(); i++) {
JSONObject commit = (JSONObject) commits.get(i);
String rawAuthor = (String) commit.get("raw_author");
rawAuthor = rawAuthor.replaceFirst(" <.*>", "");
String message = (String) commit.get("message");
String branch = (String) commit.get("branch");
messages.add(String.format("%s commited '%s' to %s (branch '%s')", rawAuthor, message, repoUrl, branch));
}
Map<String, String[]> replies = new HashMap<String, String[]>();
replies.put(chatName, messages.toArray(new String[0]));
return replies;
} catch (Exception e) {
throw new RuntimeException("Cannot parse json: " + requestBody, e);
}
}
use of net.minidev.json.JSONArray in project json-android-compare by martinadamek.
the class SmartJson method parsePublicTimeline.
public List<Map> parsePublicTimeline(InputStream inputStream) {
List<Map> result = new ArrayList<Map>();
JSONParser p = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
try {
Map map;
Set keys;
Set keys2;
JSONObject user;
JSONObject jsonObject;
JSONArray jsonArray = (JSONArray) p.parse(new InputStreamReader(inputStream));
int size = jsonArray.size();
for (int i = 0; i < size; i++) {
map = new HashMap();
jsonObject = (JSONObject) jsonArray.get(i);
keys = jsonObject.keySet();
for (Object key : keys) {
if ("user".equals(key)) {
user = (JSONObject) jsonObject.get(key);
keys2 = user.keySet();
for (Object key2 : keys2) {
map.put("user." + key2, user.get(key2));
}
} else {
map.put(key, jsonObject.get(key));
}
}
result.add(map);
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of net.minidev.json.JSONArray in project spring-boot by spring-projects.
the class BootCuriesHrefIntegrationTests method getCurieHref.
private String getCurieHref(String uri) {
ResponseEntity<String> response = new TestRestTemplate().getForEntity(uri, String.class);
JSONArray bootCuriesHrefs = JsonPath.parse(response.getBody()).read("_links.curies[?(@.name == 'boot')].href");
assertThat(bootCuriesHrefs).hasSize(1);
return (String) bootCuriesHrefs.get(0);
}
Aggregations