Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python dotGraph failed to parse JSON #235

Open
DeDiamondPro opened this issue Dec 5, 2024 · 1 comment
Open

Python dotGraph failed to parse JSON #235

DeDiamondPro opened this issue Dec 5, 2024 · 1 comment

Comments

@DeDiamondPro
Copy link

DeDiamondPro commented Dec 5, 2024

Hi,

I was trying to use the dotGraph type with python, unfortunately it seems like the JSON parser is unable to parse it.
Code to replicate, text is taken from your playground example:

import json

text = "\ndigraph G {\n    subgraph cluster_0 {\n      style=filled;\n      color=lightgrey;\n      node [style=filled,color=white];\n      a0 -> a1 -> a2 -> a3;\n      label = \"process #1\";\n    }\n  \n    subgraph cluster_1 {\n      node [style=filled];\n      b0 -> b1 -> b2 -> b3;\n      label = \"process #2\";\n      color=blue\n    }\n    start -> a0;\n    start -> b0;\n    a1 -> b3;\n    b2 -> a3;\n    a3 -> a0;\n    a3 -> end;\n    b3 -> end;\n  \n    start [shape=Mdiamond];\n    end [shape=Msquare];\n}\n"
value = json.dumps({"kind": {"dotGraph": True}, "text": text})

print(value)

This fails to parse with the following error:
image

I think this is caused by the fact that the JSON it is trying to parse seems to be double escaped, for example I would expect it to be escaped like this: label = \"process #1\", this is also what happens if I print the string, but instead the string it is trying to parse contains label = \\"process #1\\", which causes the " to not be escaped and I think that is what is causing parsing to fail.

@Klummel69
Copy link

Do not use dot-labels with text in quotation marks "" or with escape codes .
Use labels in html format, see https://graphviz.org/doc/info/shapes.html#html
Example

digraph {node [label=<Node Name<BR/>with second line>]}

The use of html brackets also works with other attributes such as style=<rounded,filled>

Also remove all "\n" characters in the graph string. At least it works for me.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants