Python: extract all words in between CRs and create JSON

I'm quite new to Python but I'm trying to figure out how to parse the data from my NAD amp and generate a JSON from it.

Here's an example what I try to do:

Data: b'\rMain.AutoSense=On\r\rMain.AutoStandby=Off\r...'

JSON: {"Main.AutoSense": "On","Main.AutoStandby": "Off"...}

And here's some sample data that I've received from the amp: b'\rMain.AutoSense=On\r\rMain.AutoStandby=Off\r\rMain.Balance=0\r\rMain.Bass=7\r\rMain.Brightness=1\r\rMain.Filters=Full Range\r\rMain.Model=C368\r\rMain.Mute=Off\r\rMain.PreoutSub=Subwoofer\r\rMain.Source=2\r\rMain.Sources=8\r\rMain.SpeakerA=On\r\rMain.SpeakerB=On\r\rMain.ToneDefeat=Off\r\rMain.Treble=6\r\rMain.Version=V1.69\r\rMain.Volume=-20.0\r\rMain.VolumeDisplayMode=Decibel\r'

Could anyone assist me with this please?

Thank you


Update: OK, managed to get a bit further:


rs232_data = rs232_data.decode('UTF-8')
settings_list = findall('\r(.*?)\r', rs232_data)

for d in range(len(setting_list)):
    print(settings_list[d])

Output:
Main.AutoSense=On
Main.AutoStandby=Off
Main.Balance=0
Main.Bass=7
Main.Brightness=1
Main.Filters=Full Range
Main.Model=C368
Main.Mute=Off
Main.PreoutSub=Subwoofer

But I'm still missing the JSON part. Anyone can help me with this part?```


from Recent Questions - Stack Overflow https://ift.tt/3r5iSld
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)