0

I extract data from a website in JSON format. When I try to parse a JSON with quotes in the body it gives me the following error.

org.codehaus.jettison.json.JSONException:

Does anybody know how I can automatically remove the quotes (the quotes around "Equity Put") in the string without removing the other quotes (like in "body").

In this example in the string of the body field the " in "Equity Put" gives the error.

{"body":"ChOTD-11/3/16 CBOE "Equity Put":Call Ratio / ISEE Call:Put Ratio Hits Extreme > 1.00 $SPY $SPX"}
2
  • 2
    Whoever generates that JSON string is doing it wrong. The " in the values need to be escaped as \". Commented Nov 3, 2016 at 18:50
  • 1
    This JSON is malformed. It's on the provider to provide well-formed JSON, and not on you as the consumer to parse malformed JSON, so whoever is providing your JSON needs to fix their output. Commented Nov 3, 2016 at 19:01

1 Answer 1

4

"Equity Put" should have been \"Equity Put\". Those quotes should have been what is called escaped, or otherwise, the string ends right before the word Equity.

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

2 Comments

But how do you put it in a script because this is a single object but how can I do it with multiple objects?
The JSON string is malformed. Whatever created that JSON string, did not do that right, or else it was changed when it was moved/converted (if any). A normal system that outputs JSON format, would have inserted the backslashes in front of the quotes inside the quoted string. You should ask the question to whoever is controlling the output, what is generating that JSON output. Perhaps it was rolled by hand and this person forgot to consider escaping quotes... String.replaceAll("\"","\\\"") might be the fix in that case. Mind you, I don't know what's going under the hood in your case.

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.