JSON

Following on from this post, I thought it might be good to think about JavaScript Object Notation (JSON).

Despite its name, JSON has evolved to be agnostic and is arguably the standard for exchanging information because its human readable and easy for computers to parse.

JSON is two things: a collection of key value pairs, and an ordered list of values. The former is easily represented with objects, dictionaries, etc. and he latter with arrays, lists, or sequences.

  • Values are string, number, object, array, true/false, or null surrounded by white-space.
  • Objects are unordered key-value pairs, represented by colon separated key-value pairs and wrapped in curly brackets.
  • Arrays are comma separated ordered collections wrapped in square brackets.
  • Comments, trailing commas, and single quoted strings are not supported.
{
    "name" : "Dougie",
    "languages" : [ "python", "java" ]
}

Python has a standard module, json, making it simple to convert Python and JSON data types. Serialisation is converting to JSON, but take care with de-serialisation as it is not quite the reverse. Not all Python data types can be converted to JSON values, so objects may not retain their original type.

This can introduce subtle problems when serialising and de-serialising:

  • JSON requires keys to be strings, so where another type is given during serialisation, it will be a string when de-serialised.
  • True serialises to true, and None serialises to null. The reverse is also true.
  • Tuple are serialised as arrays, there is no way to tell when de-serialising so you will get a list.

Serialising is done by dumping:

json.dumps(python_data)

Deserialising JSON is done by loading:

json.loads(json_data)

JSON is human readable but can be made easier to read by specifying indentation level:

json.dumps(sample_json, indent=2)

Knulli Bluetooth controller

Anbernic RG35XX H with 8Bitdo SN30 Pro Bluetooth was a bit of trial and error but got an external controller configured with Knulli.

Power on the SN30 Pro in “Windows” mode (hold Y + Start) then hold the pairing button for 3s.

In Knulli, open the menu: Controller & Bluetooth Settings > Enable Bluetooth > Pair Bluetooth Pads Automatically.

Once detected, if the controller is not responsive then you’re in a mode other than Windows.

From Controller Mapping select OK on the warning then hold any key on the SN30 Pro. Configure the keys and set either the Function key as either Star or Home on the SN30 Pro.

You’ll need then to set the active controller to SN30 Pro as P1 (or P2) controller with Controller & Bluetooth Settings > P1.

It’s not perfect but more than good enough to play games with the device connected to HDMI, which is pretty handy for a short sighted old fart.