Unicode strings in json files

I’ve decided to finally learn python. I wrote my first script today to parse the json files produced by piaware. In the process, I discovered that it seems like some of the data, weirdly, the hex code, is coded in unicode. Of all things to not encode in unicode, I would think it would be the hex code. See this example output from my script:

(‘2016-09-02 17:47:39’, ‘Hex’, u’~280762’, ‘Lat’, 31.316947, ‘Lon’, -97.258282, ‘Alt’, 7000, ‘RSSI’, -15.0, ‘Dist’, 44.32342440997429)

The “u” before the hex code indicates it’s a unicode value, if I’m understanding python correctly. Is there any reason for this?

The json files are just plain 7 bit ASCII. Any Unicode strings you are seeing are a result of whatever reading/parsing done on the python side. Maybe you are opening the file with a Unicode encoding, maybe you are using json parser that always gives you Unicode strings. Note that in your example hexid is the only field that has string data.

I would switch to python 3 as a starting point.

I thought they should just be 7 bit ASCII, so I was surprised to see unicode. Good point about that being the only string field. I’ll look into using python 3. So far, I’ve just used the Mac built-in python which on my machine is 2.7.10.

Well, that was more work than expected. For anyone else following who wants to go down this same path, if you get a warning after installing Python 3 on OSX and are having trouble installing a more recent version of Active TCL, apparently, the IDLE installer will not recognize the most recent Active TCL. Instead, it looks for the most recent 8.5 version. To fix the error, when you download the latest Active TCL, do not accept the 8.6 version that the website tries to get you to install. Instead, look for the links to previous versions, and install the most recent 8.5 version.

There were a few syntax changes, but performance is unbelievably slower on python 3, even after changes print statements to sys.stdout.write – using IDLE, that is. Using python3 at command line, though, gets the performance back.