use of net.minidev.json.parser.JSONParser in project JsonPath by jayway.
the class IssuesTest method issue_76.
@Test
public void issue_76() throws Exception {
String json = "{\n" + " \"cpus\": -8.88178419700125e-16,\n" + " \"disk\": 0,\n" + " \"mem\": 0\n" + "}";
JSONParser parser = new JSONParser(JSONParser.MODE_PERMISSIVE);
JSONAware jsonModel = (JSONAware) parser.parse(json);
jsonModel.toJSONString();
}
use of net.minidev.json.parser.JSONParser 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.parser.JSONParser in project skype-bot by toomasr.
the class Weather method getKelvinsTemp.
private Double getKelvinsTemp(String cityId) throws Exception, ParseException {
String url = baseUrl.replaceFirst("CITY_ID", cityId);
String json = URLConnectionReader.getText(url);
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
JSONObject o1 = (JSONObject) p.parse(json);
o1 = (JSONObject) o1.get("main");
Number kelvins = (Number) o1.get("temp");
return kelvins.doubleValue();
}
use of net.minidev.json.parser.JSONParser in project jmeter by apache.
the class TestJSONPostProcessor method testBug59609.
@Test
public void testBug59609() throws ParseException {
JMeterContext context = JMeterContextService.getContext();
JSONPostProcessor processor = setupProcessor(context, "0", false);
String innerValue = "{\"a\":\"one\",\"b\":\"two\"}";
String data = "{\"context\":" + innerValue + "}";
SampleResult result = new SampleResult();
result.setResponseData(data.getBytes(StandardCharsets.UTF_8));
JMeterVariables vars = new JMeterVariables();
context.setVariables(vars);
context.setPreviousResult(result);
processor.setJsonPathExpressions("$.context");
processor.process();
JSONParser parser = new JSONParser(0);
Object expectedValue = parser.parse(innerValue);
assertThat(parser.parse(vars.get(VAR_NAME)), CoreMatchers.is(expectedValue));
assertThat(vars.get(VAR_NAME + "_matchNr"), CoreMatchers.is(CoreMatchers.nullValue()));
assertThat(vars.get(VAR_NAME + "_1"), CoreMatchers.is(CoreMatchers.nullValue()));
}
use of net.minidev.json.parser.JSONParser in project ddf by codice.
the class TestLogoutService method testLogout.
@Test
public void testLogout() throws IOException, ParseException, SecurityServiceException {
KarafLogoutAction karafLogoutActionProvider = new KarafLogoutAction();
LdapLogoutAction ldapLogoutActionProvider = new LdapLogoutAction();
Action karafLogoutAction = karafLogoutActionProvider.getAction(null);
Action ldapLogoutAction = ldapLogoutActionProvider.getAction(null);
LogoutService logoutService = new LogoutService();
logoutService.setHttpSessionFactory(sessionFactory);
logoutService.setSecurityManager(sm);
logoutService.setLogoutActionProviders(Arrays.asList(karafLogoutActionProvider, ldapLogoutActionProvider));
String responseMessage = IOUtils.toString((ByteArrayInputStream) logoutService.getActionProviders(null).getEntity());
JSONArray actionProperties = (JSONArray) new JSONParser().parse(responseMessage);
assertEquals(2, actionProperties.size());
JSONObject karafActionProperty = ((JSONObject) actionProperties.get(0));
assertEquals(karafActionProperty.get("description"), karafLogoutAction.getDescription());
assertEquals(karafActionProperty.get("realm"), karafLogoutAction.getId().substring(karafLogoutAction.getId().lastIndexOf(".") + 1));
assertEquals(karafActionProperty.get("title"), karafLogoutAction.getTitle());
assertEquals(karafActionProperty.get("url"), karafLogoutAction.getUrl().toString());
JSONObject ldapActionProperty = ((JSONObject) actionProperties.get(1));
assertEquals(ldapActionProperty.get("description"), ldapLogoutAction.getDescription());
assertEquals(ldapActionProperty.get("realm"), ldapLogoutAction.getId().substring(ldapLogoutAction.getId().lastIndexOf(".") + 1));
assertEquals(ldapActionProperty.get("title"), ldapLogoutAction.getTitle());
assertEquals(ldapActionProperty.get("url"), ldapLogoutAction.getUrl().toString());
}
Aggregations