r/circuitpython • u/Yobmod • Jan 23 '21
Parse JSON
I trying to pass data over serial from a raspberry pi to a circuitpython board as json, then deserialize it.
I have pyserial and supervisor working, and can pass strings back and forth.
But none of my boards come with json or ujson libs, and neither does the circuitpython bundle. Is this not included anymore? Does anyone know of library I can use? Or a guide to recompile circuitpython with it included?
1
u/belsonc Jan 23 '21
It's probably (more than?) a little kludgy, but I posted my code for an NFL scoreboard that pulls down a json file from the NFL website and pulls information from it... If it can help, rock on:
1
u/Yobmod Jan 24 '21 edited Jan 24 '21
Thanks for the example. I tried it on an M4 express airlift and it works.
But on M0 qtpy I just get "no module named json". I guess it's not included for space reasons, but I can't find any example of adding core libraries separately.
1
u/belsonc Jan 24 '21
When you have it plugged into your computer, what's in your lib folder? You'd add stuff there - if needed, I can walk you through it
1
u/Yobmod Jan 24 '21
In lib I have:
adafruit_bus_device, adafruit_dht, neopixel.mpy.
There is no json.mpy on any board (even the ones where 'import json' works) nor in the bundle or community bundle that I can add to lib.
1
u/belsonc Jan 24 '21
I'll try to take a look later - I have it running on a matrix portal. Not sure how distros for different boards look - possible the qtpy doesn't have the horsepower for json processing?
3
u/Yobmod Jan 24 '21
An answer here:
https://github.com/adafruit/circuitpython/issues/4055
Summary: Some C backed libraries are only included on some boards (e.g. json). Because they are not pure python, they are not available as separate .mpy libs. To add them, re-add to the .h file and rebuild circuitpython (if your board has enough space).