Model.toJson doesn't escape double quotes in object keys

Hey Northwoods,

we’re running into an issue where Model.toJson doesn’t escape the double quote character (") in javascript object keys, when used in normal go.ObjectData’s.

Here’s an example that produces the bug for me in latest chrome:

<html>
  <body>
    <div id="diagram" style="width: 100%; height: 90%"></div>
    <script src="https://gojs.net/latest/release/go.js"></script>
    <script>
      const $ = go.GraphObject.make;
      const diagram = $(go.Diagram, {
        div: document.getElementById("diagram"),
        model: $(go.GraphLinksModel, {
          modelData: {
            keyValues: {},
          },
        }),
      });

      const obj = { '"': '"' };
      diagram.model.setDataProperty(diagram.model.modelData, "keyValues", obj);

      const json = diagram.model.toJson();
      console.log(json);

      try {
        // will throw
        JSON.parse(json);
      } catch (e) {
        console.warn(e);
      }

      // will throw
      go.GraphLinksModel.fromJson(json);
    </script>
  </body>
</html>

The problem is toJson returns a string containing {"keyValues":{""":"\""}} where the """ is invalid json. It escapes the object’s value fine ("\""), just doesn’t escape it in the key part.

We’re using version gojs@2.1.50 from npm (and targeting web via webpack), but this happens using the https://gojs.net/latest/release/go.js url in my example above as well.

Thanks for pointing out that bug, which has been there forever. It will be easy to fix, but I don’t have a reasonable work-around for you until the next release comes out.

I can confirm that the bug in our app as well as the example code above is now fixed from gojs release https://github.com/NorthwoodsSoftware/GoJS/releases/tag/v2.1.53

Thanks walter!

Thanks for the confirmation. Sorry for the inconvenience.