-1

I have the string:

'[\'{"cx":3575,"cy":1657,"r":98}\', \'{"cx":3284,"cy":1706,"r":81}\', \'{"cx":4260,"cy":1611,"r":97}\', \'{"cx":3350,"cy":1632,"r":60}\', \'{"cx":3475,"cy":1586,"r":77}\', \'{"cx":4243,"cy":1474,"r":87}\']'

How I can get correct array of dicts from this?

Dmitry Sokolov
  • 1,303
  • 1
  • 17
  • 29

1 Answers1

0

Could you do something like this?

import ast

string = '[\'{"cx":3575,"cy":1657,"r":98}\', \'{"cx":3284,"cy":1706,"r":81}\', \'{"cx":4260,"cy":1611,"r":97}\', \'{"cx":3350,"cy":1632,"r":60}\', \'{"cx":3475,"cy":1586,"r":77}\', \'{"cx":4243,"cy":1474,"r":87}\']'

# Convert string to list
arr = ast.literal_eval(string)

# Convert list of strings to list of dicts
arr = [ast.literal_eval(item) for item in arr]
PCDSandwichMan
  • 1,964
  • 1
  • 12
  • 23