0

I am trying to process a JSON of the following format in Java.

    String flowJSON = "{\"FlowDTO\":[{\"policyName\":\"Firewall\",\"action\":\"DROP\",\"sourceIp\":\"ANY\",\"destinationIp\":\"ANY\",\"datapathId\":\"8506829779379520\",\"sourcePort\":\"ANY\",\"destinationPort\":\"78\",\"protocol\":\"TCP\",\"priority\":\"0\",\"rateLimiter\":\10000\"}]}";

JsonNode root = mapper.readTree(flowJSON); 

For the above code, I am getting the below error. However, I don't understand why the incorrect character is '@' when I do not have that character in my JSON. Am I not reading this error correctly?

[2014-08-15 14:44:37.095] ERROR POLLtimer                    System.err                                                        com.fasterxml.jackson.core.JsonParseException: Unexpected character ('@' (code 64)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') 
[2014-08-15 14:44:37.095] ERROR POLLtimer                    System.err                                                         at [Source: java.io.StringReader@4e511927; line: 1, column: 214] 
[2014-08-15 14:44:37.096] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1378) 
[2014-08-15 14:44:37.096] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:599) 
[2014-08-15 14:44:37.096] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:520) 
[2014-08-15 14:44:37.097] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleUnexpectedValue(ReaderBasedJsonParser.java:1387) 
[2014-08-15 14:44:37.097] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:678) 
[2014-08-15 14:44:37.097] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:194) 
[2014-08-15 14:44:37.098] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeArray(JsonNodeDeserializer.java:230) 
[2014-08-15 14:44:37.098] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:202) 
[2014-08-15 14:44:37.099] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:58) 
[2014-08-15 14:44:37.099] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:15) 
[2014-08-15 14:44:37.099] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2793) 
[2014-08-15 14:44:37.100] ERROR POLLtimer                    System.err                                                         at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:1659) 
[2014-08-15 14:44:37.100] ERROR POLLtimer                    System.err                                                         at com.hp.sf.impl.fucms.PollFlowTimerTask.run(PollFlowTimerTask.java:95) 
[2014-08-15 14:44:37.101] ERROR POLLtimer                    System.err                                                         at java.util.TimerThread.mainLoop(Timer.java:555) 
[2014-08-15 14:44:37.102] ERROR POLLtimer                    System.err                                                         at java.util.TimerThread.run(Timer.java:505) 
1
  • 1
    The way to figure this out would be to print out flowJSON (so the escapes are gone) and feed it through one of the online JSON parsers. Commented Aug 15, 2014 at 22:13

2 Answers 2

4

You're missing a double quote here: \"rateLimiter\":\10000\".

The \100 is being treated as a single character expressed in octal. If you look at an ascii table you'll see that character 64 (100 in octal) is an @ symbol. So you're string contains "rateLimiter":@00" instead of "rateLimiter":"10000"

Sign up to request clarification or add additional context in comments.

Comments

1

The last number in your string is missing a quote:

\10000\"

to

\"10000\"

You can use http://jsonlint.com/ in the future for JSON validation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.