Showing posts with label json. Show all posts
Showing posts with label json. Show all posts

Monday, July 14, 2014

Low-Level JSON Parsing With Jackson

Jackson is primary used for mapping Java classes to JSON objects. However, there are times where you need to retrieve the raw text content of a specific JSON node rather than to map the entire document to a class.

This can be done with the following code:

ObjectMapper mapper = new ObjectMapper();
JsonFactory factory = mapper.getJsonFactory();
JsonParser jp = factory.createJsonParser(jsonString);
JsonNode node = mapper.readTree(jp);
JsonNode node1 = node.get(“key1”);
JsonNode node2 = node2.get("key2");
String node2Content = node2.asText();

References:

Sunday, July 13, 2014

JSON Date Representation

When Javascript serialises an Date object in JSON, it will be represented in the following format:

2014-02-28T16:00:00.000Z

This means that when the user keys in a date on a web-form, and it gets submitted to the server, the exact time saved on the server contains time-zone information. In some applications, this may result in the date being off by 1 days when this date is subsequently used for processing, specifically in situations where you only really needed the date and not the time.

In the above example, it is actually 2014-03-01 in time-zone +0800. If the time is truncated, the processing will use 2014-02-28 instead.

If you want the date to be time-zone neutral, consider submitting the data to the server as a formatted date string of your choice.

Tuesday, December 4, 2012

Processing JSON Response in JMeter

This is a simple and somewhat limited way to do this. You will be able to extract individual values pretty easily but if you want a comprehensive data model of the JSON data structure, this isn't the way to go. If the same property name is used in multiple objects within a JSON data structure, this won't work as well.

Basically this method uses Regular Expressions (using JMeter's Regular Express Extractor) to extract individual values that you're looking for specifically.

Link: http://alexandru-ersenie.com/2009/09/14/json-and-jmeter-extract-json-response/

For more complex requirements, someone has posted about using the BSF PostProcessor and Javascript.

Link: http://www.havecomputerwillcode.com/blog/?p=500