1
votes

I am trying to get a string that is the following format converted to a dictionary. it is in the from of a json but it is, by type, one continuous string. My goal is to turn it into a list of dictionaries. I have tried using split but that ADDS [] when it already has them. this variable is NOT in a json file and will always initially be a string in the script it exists in. I use a function to get it into a variable as a string. from there I need to make it a list of dictionaries.

The large amount of quotes are unimportant as a previous answer informed me that 'abc''def' in python is the same as 'abcdef'. the "" ARE a part of the data so "title" and all other words with "" around them will retain those quotes.

'['
            '{'
            ' "title": { "text": "Test Title" }, '
            ' "axisX": {'
            '            "title": "Time", '
            '            "valueFormatString": "hh:mm:ss.sss", '
            '            "nMajTicks": "11", '
            '            "nMinTicks": "0", '
            '            "minimum": "0", '
            '            "maximum": "10" '
            '          }'
            '}'
']'

I was wondering if there is a library function for this in python or if im going to have to iterate thru the string and look for specific characters to create key item pairs. Thank you!

this looks like JSON, a text-based serialization format. Note, this would be deserialized into a list, although a list with a single item, a dictionary.\ - juanpa.arrivillaga
Does this answer your question? JSON String conversion to Dict - NelsonGon
I assume there's a missing closing quote on the third linen from the end. But yeah, this is JSON. Remember that Python treats 'abc' 'def' as 'abcdef'. What you have above is just a single string with no newlines. - Frank Yellin
Are all the ' characters literally in the data, or is this just how you wrote it as a Python literal? - Barmar
"...will always initially be a string in the script it exists in. I use a function to get it into a variable as a string." Show this script/function. And yes there is a library and json.loads() will convert a JSON string to a Python object. - Mark Tolonen