MT-JSON Conversion

Back and forth conversion between MT messages and JSON

Different JSON structures are created depending onf the model object where the toJson is invoked.

When SwiftMessage#toJson() in the backbone model is used, the generated JSON contains a generic structure with plain name/value tuples for the text block as in the example below.


{ "version" : 1, "timestamp" : '2017-06-05 04:32 -0300', "data" : {
    "block1" : {
        "applicationId" : "F",
        "serviceId" : "01",
        "logicalTerminal" : "BICFOOYYAXXX",
        "sessionNumber" : "8683",
        "sequenceNumber" : "497519"
    } ,
    "block2" :  {
        "messageType" : "103",
        "senderInputTime" : "1535",
        "MIRDate" : "051028",
        "MIRLogicalTerminal" : "ESPBESMMAXXX",
        "MIRSessionNumber" : "5423",
        "MIRSequenceNumber" : "752247",
        "receiverOutputDate" : "051028",
        "receiverOutputTime" : "1535",
        "messagePriority" : "N"
    } ,
    "block4" : [
        { "20" : "0061350113089908" },
        { "13C" : "/RNCTIME/1534+0000" },
        (...)
        { "72" : "/BNF/TRANSF. BCO. FOO" }  ]
    }
}

If the message is parsed into the AbstractMT using AbstractMT#parse or by creating any of the subclasses such as the MT103, then a call to toJson() generates a similar structure, but for the text block each field is serialized into a specific structure.


{
  "type": "MT",
  "basicHeaderBlock": {
    "applicationId": "F",
    "serviceId": "01",
    "logicalTerminal": "AAAABEBBAXXX",
    "sessionNumber": "0001",
    "sequenceNumber": "000001"
  },
  "applicationHeaderBlock": {
    "receiverAddress": "BBBBBEBBXBIL",
    "messagePriority": "N",
    "messageType": "565",
    "blockType": "I",
    "direction": "I"
  },
  "userHeaderBlock": {
    "fields": [
      {
        "name": "108",
        "mUR": "495"
      }
    ]
  },
  "textBlock": {
    "fields": [
      {
        "name": "16R",
        "blockName": "GENL"
      },
      {
        "name": "20C",
        "qualifier": "CORP",
        "reference": "ABCD1234"
      },
      {
        "name": "20C",
        "qualifier": "SEME",
        "reference": "123456789124001"
      },
      {
        "name": "23G",
        "function": "NEWM"
      },
      {
        "name": "22F",
        "qualifier": "CAEV",
        "indicator": "CONV"
      },
      {
        "name": "98C",
        "qualifier": "PREP",
        "date": "20210912",
        "time": "123111"
      },
      {
        "name": "16R",
        "blockName": "LINK"
      },
      {
        "name": "22F",
        "qualifier": "LINK",
        "indicator": "INFO"
      },
      {
        "name": "13A",
        "qualifier": "LINK",
        "numberId": "564"
      },
      {
        "name": "20C",
        "qualifier": "RELA",
        "reference": "NONREF"
      },
      {
        "name": "16S",
        "blockName": "LINK"
      },
      {
        "name": "16S",
        "blockName": "GENL"
      },
      {
        "name": "16R",
        "blockName": "CAINST"
      },
      {
        "name": "13A",
        "qualifier": "CAON",
        "numberId": "002"
      },
      {
        "name": "22F",
        "qualifier": "CAOP",
        "indicator": "CONY"
      },
      {
        "name": "35B",
        "qualifier": "ISIN",
        "iSIN": "LU0123456789",
        "description": "ABCD CORP ORD SHS"
      },
      {
        "name": "36B",
        "qualifier": "QINS",
        "quantityTypeCode": "FAMT",
        "quantity": "50000,"
      },
      {
        "name": "16S",
        "blockName": "CAINST"
      }
    ]
  }
}

Finally, there also axist yet another JSON structure if serialization is done using the persistence model MtSwiftMessage