Skip to content

generateJSON.py Documentation

Introduction

generateJSON.py is a tool in Nobius that allows Mobius' Group files to be converted back to JSON files. This is useful if small changes need to be made to a question or group, as they can be made within the Mobius editor online, and the JSON files can be updated using this script on the updated Group file.

Note this tool will only work on Group files generated by the Nobius toolset. This is to preserve the structure of the JSON file as well as ensure the conversion process is robust.

Prerequisites

In order to use this tool, python 3.6 or higher is required. Additionally a few modules need to be installed:

  • bs4 or BeautifulSoup. This is a parser used to get html and xml attributes from the question files.
  • lxml. This is a toolkit used in conjunction with BeautifulSoup to parse the xml.

Both these modules can be installed used pip:

python -m pip install bs4 lxml

Usage

To use this tool, call the file through python within the Sheet Generator folder:

python generateJSON.py FILEPATH -d DESTINATION --no-uid

Where:

  • FILEPATH is a required argument, showing the path to the xml file to be converted.

  • DESTINATION is an optional argument, given by the -d or --destination flag, telling the script where to write the JSON files to. By default, this is the same directory as the target xml file.

  • --no-uid is an optional flag, telling the script to remove all uid, modifiedBy and school properties from the JSON files. This is incase you wish to create a completely new group that will not overwrite the current one in Mobius.

The script will print useful information, indicating what properties were missed. These will be replaced with a null value in the JSON if the property could be nested, but its value is unknown. The html element where the value is expected to be will be printed, allowing the user to fill in the missing information in case it is a fault of the script.