MiniM. Saving time.

| About | Download | Tools | Knowledge Base | How to Buy |

MiniM Overview

Getting Started




Cache Tools

GT.M Tools

Knowledge Base




MiniM Knowledge Base | May 17, 2016

MiniM + JSON

How to get data in JSON format from the MUMPS?

Tony Toucan ( wrote on the MUMPS encoder of ordinal MUMPS structures into the JSON format. See detailed description at SON)_Builder. And this code can be adopted to any MUMPS implementation, which does not contain JSON support by default.

If routine from Tony Toucan is main part on the server side, on the client side main technology are Javascript and detailed description of JSON from W3C, for example: JSON Tutorial from W3SCHOOLS.

To get data in the MUMPS code we can get data from MWA page where we call MUMPS to get data and encode it in the JSON format. See set of JSON examples files at

Routine %JSON must be imported into the "%SYS" database of MiniM and is accessible from any database becouse name starts with the percent symbol.

File jsonstart.html is root file which call two json examples: static file json.txt and dynamic MWA page json.mwa.

Example uses builtin Javascript object JSON. This object is builtin in the modern WEB browsers Firefox 3.5, Internet Explorer 8, Chrome, Opera 10, Safari 4. For older browsers, a JavaScript library is available at ckford/JSON-js.

Also, older browsers without the support for the JavaScript function JSON.parse() can use the eval() function to convert a JSON text into a JavaScript object:

var obj = eval ("(" + text + ")");

JSON example calls static JSON data using


This file contains one simple object

  "name": "Simpson"

And second JSON example calls dynamic JSON generator


This file contains of two lines:

<?exec s data("name")=$zv ?>
<?eval $$FromArray^%JSON("data") ?>

Here first line constructs data with property "name" and assign value of current MUMPS version. And second line outputs given data as HTTP responce.

After both JSON downloaded and parsed, html page shows info about JSON object:

// low-level function, call server by given url
function getjson(url)
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status ==  200) {
        var getobj = JSON.parse(xmlhttp.responseText);
  };"GET", url, true);

// this event fired after JSON object downloaded from the server
// and parsed as a Javascript object
function show_object(getobj)
  document.getElementById("output").innerHTML = 
    "We got info about object with name: " +;
  return false;

For showing data this code replaces inner HTML code of HTML object with name "output":

<p id=output></p>

This is very simple example how to generate on the MUMPS side and get to the WEB browser side data in the JSON format. Real complex applications differ by using more complex data. See MWA documentation how to handle CGI variables sent by the WEB browser and JSON Tutorial how to handle embedded objects and arrays of JSON.

Download set of JSON examples files:

Eugene Karataev

Copyright (C) Eugene Karataev
Info Support