1

i'm using node.js. i have a python dictionary returned from elasticsearch log:

{'name': 'dan',
 'age': 38,
 'color': 'green',
 'hobbies': None, 
 'message': 'this message has quotes in it \' so i cannot replace all single quotes', 
 'happy': True}

how can i parse this in javascript? i have tried this regex solver but he could not deal with the True/False or None values, and kinda looks funky:

 const regex = /('(?=(,\s*')))|('(?=:))|((?<=([:,]\s*))')|((?<={)')|('(?=}))/g;
str = str.replace(regex, '"');
str = JSON.parse(str);

any ideas would be very helpful. Thanks!

Gidinated
  • 11
  • 1
  • 1
    Is there some way you can get it to log JSON instead of Python syntax? – Barmar Oct 03 '22 at 16:31
  • The proper solution is to [make Python log as JSON](https://stackoverflow.com/q/48170682/1048572). Then you can parse the log using any language. – Bergi Oct 03 '22 at 19:23

0 Answers0