Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Import Error: No Json Module
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Import Error: No Json Module

by john_doe1337 on Mon Mar 23, 2020 9:07 am

Settings:
Adafruit CircuitPython 5.0.0 on 2020-03-02; Adafruit Feather M0 Adalogger with samd21g18

Problem:
import json throws an error: "No module named json". All other moduls work (ie: time, busio, board, digitalio)

I checked this out: https://learn.adafruit.com/adafruit-pyp ... -libraries, and thought about importing the json lib manually, but there is no json.mpy or simular.

What am I missing?

john_doe1337
 
Posts: 2
Joined: Mon Mar 23, 2020 8:51 am

Re: Import Error: No Json Module

by dastels on Mon Mar 23, 2020 12:15 pm

The JSON module is implemented in C++ inside the CircuitPython runtime. Several low level or performance-sensitive modules are like that. In these cases there is no MPY file.

Due to memory constraints, not all are available on the SAMD21/M0 builds. The json module is one of those.

Dave

dastels
 
Posts: 3102
Joined: Tue Oct 20, 2015 3:22 pm

Re: Import Error: No Json Module

by john_doe1337 on Mon Mar 23, 2020 12:40 pm

The JSON module is implemented in C++ inside the CircuitPython runtime.


So, is it possible to parse json anyhow on a samd21g18?

john_doe1337
 
Posts: 2
Joined: Mon Mar 23, 2020 8:51 am

Re: Import Error: No Json Module

by dastels on Mon Mar 23, 2020 1:23 pm

The alternatives I see:

1) If your JSON data is simple enough, you might be able to do a very simple scanning "parser". You would want/have to avoid building up much structure in RAM, instead scanning and extracting only the data you needed. Even then, I can't say if it would fit since there's the code to do that as well. Of course it depends on how much other code (and data) you have in RAM.

2) Build a custom version of CircuitPython that has the json module enabled. But... depending on your memory usage you may not have room to use it.

3) Switch to C++. The "problem" with circuiutpython is that the python code (yours as well as any MPY libraries you import) is stored in RAM, and the SAMD21 doesn't have much.

4) Switch to a Feather M4 Express or nRF52840 board and an Adalogger wing (https://www.adafruit.com/product/2922). The Feather STM32F405 is an alternative as well and has an onboard microSD.

Dave

dastels
 
Posts: 3102
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.