A JSON Decoding Extension for App Inventor

A JSON Decoding Extension for App Inventor


– Stars (0)


Version: 1.0

Last Updated: 16-09-2019 14:55


A JSON Decoding Extension for App Inventor (1)

[This Extension and  its doc are available. Please see the bottom of this article.] JSON format is commonly used when receiving data from Web services, etc. With App Inventor, JsonTextDecode in the web block can convert JSON to list structures. Then, the conversion result can be manipulated by the selectItem and lookUpInPairs of the list block. However, as Evan W Patton (MIT) pointed out in the paper [1], these list processes are generally very complicated. And he also suggested a more readable and compact Extension block to alleviate this. I independently developed an Extension for JSON decode based on his new block idea. This Extension might be intuitive and easy to understand because it can hierarchically acquire necessary information with the tag names (properties) without using complicated operations on nested lists. The outline is shown in the figure below. (please enlarge and see the figure.)

This Extension takes two arguments. One is JSON data that was converted into list structure. The other is a search instruction list for hierarchically specifying the value of a specific tag (property). In this example, JSON text holds the values ​​of four kinds of sensors as ”healthData”. In the above figure, the name of the third sensor is specified. Note that in the query list, a number such as ”3” indicates the element index of the JSON array structure. Query List : John, healthData, 3, sensor Result : Systolic pressure JSON data used here is a modified version of the health data published in the following document [2]. The following figure shows the part of listing up all four sensors and their values ​​using this Extension. I think that it is written concisely. Operations for complicated list processing are not appeared here.

Collecting values of the four sensors
An example of running this application is shown below. For details, please see the files shown below.

Result of the test program on Android

Within this Extension, the list structure is iteratively processed using the function of YailList [3]. I think that YailList makes somewhat relaxation of complicated data type conversion (casting)  in JAVA. This Extension is still in beta. Although some of the JSON structures have been tested, all the structures are not covered, so bugs may be included. However, it is shown below for your reference. It was tested with Nexus 6 (Android 7.1.1). This extension was created using AppyBuilder Code Editor [4].
[1] JSON Interoperability in MIT App Inventor https://2018.splashcon.org/event/blocks-2018-papers-json-interoperability-in-mit-app-inventor [2] http://georgepavlides.info/ehealth-made-simple/ [3] http://3nportal.com/AIBridge/API/com/google/appinventor/components/runtime/util/YailList.html [4] AppyBuilder Code Editor http://Editor.AppyBuilder.com

Leave a Reply

Your email address will not be published.