Skip to content

Instantly share code, notes, and snippets.

View craigsdennis's full-sized avatar

Craig Dennis craigsdennis

View GitHub Profile
@craigsdennis
craigsdennis / pythonDictParser.js
Last active June 28, 2024 12:48
Convert Python String to JSON
// Thanks ChatGPT!
// Getting back a Python dictionary in JavaScript, and need it to be JSON
function pythonDictToJson(pythonDictString) {
// Regular expression to match and replace Python literals
const regex = /('(\\'|[^'])*')|None|True|False/g;
// Replacer function to handle each match
const replacer = (match) => {
if (match === 'None') {
return 'null';