3

I'm putting in JSON into an SQL table (type: json) and it claims something is wrong - but I can't tell what it's pointing out directly.

Current json I'm trying to input:

'{"{\"type\":\"HUMAN\"}":"1.0"}'

Yes, it is "json within json" but the code I'm writing is kind of dependent on it being that way. I'm not willing to really change that part.

Here's the error:

#3140 - Invalid JSON text: "Missing a colon after a name of object member." at position 5 in value for column 'mines.materials'.

If you need code, I have it. I really need to know whats wrong with the JSON, if it requires a fundamental change to the code I can provide what I have.

2
  • That isn't valid JSON at all. If you pass it to JSON.parse in your browser, it throws. Use \\" not \". Commented Dec 9, 2017 at 3:29
  • that seemed to do the trick. JSONObject#toJSONString uses single back-slashes Commented Dec 9, 2017 at 3:34

1 Answer 1

3

You should really try validating some basic assumptions.

'{"{\"type\":\"HUMAN\"}":"1.0"}' is not a valid JSON string as you can see below

"use strict";
(function () {
  try {
    JSON.parse('{"{\"type\":\"HUMAN\"}":"1.0"}');
  } catch (e) {
    console.error(e);
  }
}());

You are using attempting to use a JSON encoded string as a property key in another JSON encoded string but have not escaped it correctly.

You need to use \\" instead of \" to escape the quotes

"use strict";
(function() {
  try {
    console.log(JSON.parse('{"{\\"type\\":\\"HUMAN\\"}":"1.0"}'));
  } catch (e) {
    console.error(e);
  }
}());

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

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.