The JsonWeb module allows to create websites directly using json data. Using templates we can specify the structure of the website, and then JsonWeb automatically create a corresponding website with data extracted from json files.
This module has been built for portability and ease of use, so it is composed by a stand-alone Python program. All you need is to have Python 3 installed on your system, then you can just download the code and run it. The behavior of the module can be tuned by using some command options that are described below. Being a Python program, it is also easy to inspect the code, see how it works, and possibly modify it if you want so.
Command line: jsonweb
The JsonWeb module can be directly launched without any parameters: if so, it will proceed by using default locations for the input, templates and output directories (see below).
The JsonWeb behaviour can be modified via the following command line options (shorter or longer formats):
-h, --help show this help message and exit
-i INPUT, --input INPUT
the input json directory (default: google/results)
-t TEMPLATES, --templates TEMPLATES
the templates directory (default: templates)
-o OUTPUT, --output OUTPUT
the output web directory (default: website)
-b BASE, --base BASE base directory for relative directory paths (default: .)
-l LEFT, --left LEFT left delimiter of JsonWeb command activator (default: [[[)
-r RIGHT, --right RIGHT
right delimiter of JsonWeb command activator (default: ]]])
-a [ALLOWED [ALLOWED ...]], --allowed [ALLOWED [ALLOWED ...]]
allowed file extensions: files are processed (default: ['.html', '.htm'])
-d [DISALLOWED [DISALLOWED ...]], --disallowed [DISALLOWED [DISALLOWED ...]]
disallowed file extensions: files are ignored (default: ['~'])
-c, --copy copy all other files (not in allowed+disallowed) (default: False)
-g, --gzip compress allowed output pages with gzip (adds .gz suffix) (default: False)
Some more information about the options:
-i, --input
-t, --templates
-o, --output
-b, --base
-l, --left
-r, --right
-a, --allowed
-d, --disallowed
~. This option works also in combination with option -c, disabling copy. So, every file whose extension is specified by this option will never be copied to the output directoy.
-c, --copy
-g, --gzip
Note that JsonWeb, when generating the output files and copying, also automatically replicates the directory structure present in the templates. Thus, this allows for complete nested structures to be generated, not only flat lists of pages.
As said, JsonWeb generates a web site using templates and json data. The templates are constituted by the pages of the web site, with the added condition that they can contain special JsonWeb commands that are processed and that produce corresponding pages with values extracted from the json data. The commands are contained within the delimiters [[[ and ]]] (that can also be changed via the appropriate command line option, so not to interfere with the language of the page). In order to extact data, we use json paths, that is to say key values that are dot-separated (so, for example, using the Mobosearch App Interchange Format writing "app.developer.name" corresponds to enter the json with key "app", then with key "developer", and finally extracting the value corresponding to the key "name").
The basic JsonWeb commands are three, defined as follows:
[[[context:path]]]
, where path is the json path corresponding to the data to consider. For instance, if we have data in the MoboSearch app interchange format and we want to tell JsonWeb that the data to extract must come from all the app data structures therein, we can use [[[context:app]]]
: this is telling JsonWeb to process the json files and to consider the json substructures within the appkey.
[[[context:app]]]
as described above, inserting [[[filename:id]]]
tells the JsonWeb generator to produce a file that has as name the json value of app.id
(the store id of the app).[[[path]]]
. This tells the JsonWeb generator to use the json value corresponding to the specific path (always within the specified context). Going on with the example before, writing [[[name]]]
(within a context [[[context:app]]]
) tells JsonWeb to insert the json value corresponding to the app.name
path, that is to say the name of the app.
So, for example, if we were using json app data in AIF format we could have in the template the following web page describing an app:
<!DOCTYPE html> <html> <body> [[[context:app]]][[[filename:id]]] <script> <!-- as an example, here we also insert the raw json into a variable mydata, that can be used by the js --> mydata=[[[.]]] (other js code...) </script> <h1>The App: [[[name]]]</h1> <p>Here you can find the info for the app <q>[[[name]]]</q>.</p> <p>First of all, the number of total reviews for this app is: <strong>[[[reviews.total]]]</strong>.</p> (other html code...) </body>
This single page template would then, via JsonWeb, automatically generate description pages for all the apps.
The source code of the module can be directly downloaded here (note that at public launch we will also provide a GitHub link).