Easy StandardXML To JSON

Recemt commits to OpenGroupware Coils add a new jsonWriteAction action for OIE workflows. OIE has long had readJSON for serializing arbitrary JSON documents into XML. jsonWriteAction adds the ability to serialize StandardXML data into JSON documents [provided all the data-types represented in the StandardXML document can be persisted in JSON]. Date and date time values will be serialized as strings in the YYYY-MM-DDTHH:MM:SS format; date values will have a time value of "00:00:00'". The __jsonWriteAction_ requires no parameters - it simply transfoms the entire input message into JSON.

<action name="actionActivity" id="00020" extensionAttributes="XLSToJSONMailBack/00020">
  <input property="JSONData" formatter="StandardRaw"/>
  <output><source property="XLSData"/></output>
  <attributes>
    <extension name="activityName">writeJSONAction</extension>
  </attributes>
</action>

Text 1: The contents of the message "XLSData" is serialized to an application/json message labeled "JSONData".

The row elements from the StandardXML data stream will persisted into the rows key of the JSON document with each element of that array containing a keys and fields array. Keys contain the attributes of the row which where indicated to be primary keys while fields contains the non-idempotent field values. This maintains the meta-data at least of the record identity which in StandardXML would be encoded in element attributes [JSON having no concept of value attributes cannot express this information].

 {"formatClass": null,
 "formatName": null,
 "rows": [
     {"keys": {},
      "fields": {
        "comment": null,
        "fs_net_price": 72.0,
        "fs_discount": 0.4,
        "dexription": "Brace",
        "no_": "000-0005",
        "x2011_list": 120.0}},
     {"keys": {},
      "fields": {
        "comment": null,
        "fs_net_price": 85.98,
        "fs_discount": 0.4,
        "dexription": "Diamond Brush Template, 13\"",
        "no_": "000-0010",
        "x2011_list": 143.3}} ]
    ...
 "tableName": null,
 "rowCount": 6330}

Text 2: A JSON representation of a StandardXML message created via the xlsToXmlAction - a message having no format name, format class, or target/source table. No elements of the row are indicated to be keys so all columns are represented as fields.

The target/source table as well as the format information will be presented in the JSON data as outermost keys. If the StandardXML was generated from arbitrary XML [such as the use of xlsToXmlAction] these fields may be null. The total row count is also presented as an outermost key avoiding the need to clients to iterate the entire value of rows in order to present a count.

Thanks to the new writeJSONAction the job of shipping row and field oriented data off to a web application is now trivial.