0

I'm using python to create a json string such as:

jsonData = '{id: "idStr", name: "nameStr"}'
prs = json.loads(json.dumps(jsonData))

I then use flask to render my html template and pass in the prs variable as the value to create my data table. However, I need the quotations around idStr and nameStr to remain quotation marks. Instead they convert to #&34; in my html file. I was just wondering if there was a simple method to accomplish this or if I am just going at it the incorrect way.

The reason why I need the quotes for the values is because I'm using AnyChart to create a Gantt Chart visualization.

Output:

data = [{id: #&34;idStr#&34;, name: #&34;nameStr#&34;}]
lugz
  • 1
  • 1
  • Can you make it an object? Must it be a string? like so: `jsonData = {...}` – user3875913 Jul 08 '21 at 20:05
  • have you tried using `\"` instead of `"` ? or using triple-quotes instead of single quotes? – Sina Jul 08 '21 at 20:10
  • the Python part does not make much sense to me. How it differs from `prs = jsonData`? – VPfB Jul 08 '21 at 20:15
  • So I'm using AnyChart to create a gantt chart using javascript, and so the data object in AnyChart is created like: `data = [{ id: "ProjectID", name: "ProjectName",}]. so the value for each field has to be in quotations. New to JS so apologies. – lugz Jul 08 '21 at 21:30
  • @Sina yea i tried using the backslash and triple quotes but it just converts the quotes to the #&34; like usual – lugz Jul 08 '21 at 21:35
  • What anychart produces is a JavaScript Object - not JSON. It is not valid JSON since the property names does not have qoutation marks. – fredrik Jul 08 '21 at 21:40
  • This answer from the duplicate should help: https://stackoverflow.com/a/23071187/218196 – Felix Kling Jul 08 '21 at 21:42
  • @FelixKling, do you think it is even possible then to use JSON to help create an AnyChart JavaScript Object from Python input? I took a look at the duplicate and the "tojson" filter did allow for the array to be passed through, but requires quotations around the property names like fredrik stated. – lugz Jul 08 '21 at 22:37
  • I think the concerns about quotation marks are irrelevant if you use the `tojson` filter. – Felix Kling Jul 09 '21 at 08:02

0 Answers0