Working with JSON Configurations

Developing Solutions provides a RESTful API to control dsTest as an aid to automated testing. If you choose to use REST with dsTest, you will be working with JavaScript Object Notation (JSON) rather than XML when configuring dsTest and when issuing commands. This topic focuses on converting your existing XML documents to JSON and creating new JSON configurations. See Using the RESTful API for more information about communicating with dsTest using REST.

When a transparent data element (i.e., data that is included in a message but not interpreted by dsTest) contains XML the contents will also be converted to JSON. You will need to restore the original XML content.

Elements that may occur more than once in a structure are only contained within an array if there are multiple occurrences present. If you add additional occurrences be sure to surround all occurrences with square brackets ([]) to define an array.

In the RESTful API different message types are used for configuration and command elements, unlike sourcing a test using XML - where commands may be loaded at the same time as the configuration.

Converting XML to JSON

dsClient Terminal provides a conversion command - xmlToJson - that translates a valid XML document into a JSON object.

xmlToJson <input path and file>

The resulting file will be named <input file name>.json and will be written to the same directory containing the input file.

Converting XML to Postman Format

dsClient Terminal also provides a conversion command - xmlToPostman - that converts a valid XML document into a JSON object that can be imported into the Postman application as a Postman Collection. The advantage of using this method is that the URL, method, headers, and message body, if any, are all provisioned when imported. You can then drag the resulting message into the collection you're building. You can convert commands as well as configurations as long as they are complete XML documents. If you're working with a dsClient Desktop Workspace, you can open your commands, one at a time, export to XML using the To XML... button, transfer to your server, and then convert each command into a collection.

xmlToPostman <input path and file>

The resulting file will be named <input file name>.json and will be written to the same directory containing the input file.

Creating JSON Configurations

JSON is a method of representing structured data objects as collections of name/value pairs, also referred to as the members of an object. The name of a member is often referred to as its key and we will do so going forward. Values may be simple - string, numeric (decimal only), boolean, or null - or complex structures - objects or arrays. Colons (:) separate keys from values and commas (,) separate the members of complex structures. Keys and simple values are always enclosed in quotes ("). An object's collection of members is considered to be its "value" and that value is enclosed in braces ({}). Arrays are enclosed in square brackets ([]). White space (blank spaces, tabs, and returns) is allowed before and after braces, brackets, commas, and colons.

JSON configurations must conform to the same schema that is used for XML configurations. Member keys must use the same tag names, must appear in the same order, and are governed by the same content and occurrence rules as XML elements. dsTest translates between XML and JSON using the following rules:

Complex content elements - elements that may contain child elements - become objects in JSON and their attributes and child elements become members of the object. These complex structures may be contained within other objects, in which case they become members with object values, or they may be contained in arrays.

Simple content elements - elements that have string, numeric, or boolean values - become members with simple values unless they also have attributes. In that case they have object values comprised of attribute members plus a _value member to convey the simple value.

Multiple occurrence elements - elements that may appear multiple times under the same parent - become one of the structures described above depending on the type of element. If more than one instance is configured, the elements must be contained within an array. dsTest does not require that single instances be enclosed in brackets.

Attributes - attributes as such do not exist in JSON and so they must become members. Attribute keys must be prefixed with an at sign (@) in order to separate them from element members.

The annotated JSON snippet below contains examples of each of the structures described above.

"subscriber_database":          (complex content element)

  {

    "@count":"20",          (attribute)

    "@name":"amf_subs",

    "subscriber_profiles":

      {

        [          (begin array)

          "authentication_profile":

            {          (begin object)

              "@name":"5g_auth",

              "auth_type":"5gAKA",          (simple content element with simple value)

              "auth_algorithm":"Milenage",

              "amf":"0xfffe",

              "gen_vectors":"2",

              "request_vectors":"5"

            },          (end object)

          "authentication_profile":

            {

              "@name":"4g_auth",

              "auth_type":"EUTRAN",

              "auth_algorithm":"Milenage",

              "gen_vectors":"2",

              "request_vectors":"5"

            }

        ],          (end array)

        "subscription_profile":

          {

            "@name":"subscription_profile",

            "network_access_mode":"0",

            "roaming_restricted":"true",

            "status":"0"

          }

      },

      [

        "subscriber_group":

          {

            "@start":"1",

            "@end":"10",

            "@name":"5g_subs",

            "group_profiles":

              {

                "authentication_profile":"5g_auth",

                "subscription_profile":"subscription_profile"

              },

            "identities":

              {

                "imsi":"310410167772161",

                "imei":"12341234000000",

                "software_version":"01"

                "msisdn":

                  {

                    "noa":"1",

                    "npi":"1",

                    "number":"167772161"

                  },

                "ip_address":          (simple content element with attribute and value)

                  {

                    "@incr_by":"1",

                    "_value":"10.1.1.1"

                  },

                "key":"0x000102030405060708090a0b0c0d0e0f",

                "op":"0x63bfa50ee6523365ff14c1f45f88737d"

          },

        "subscriber_group":

          {

            "@start":"11",

            "@end":"20",

            "@name":"4g_subs",

            "group_profiles":

              {

                "authentication_profile":"4g_auth",

                "subscription_profile":"subscription_profile"

              },

            "identities":

              {

                "imsi":"310410167772171",

                "imei":"12341235000000",

                "software_version":"01"

                "msisdn":

                  {

                    "noa":"1",

                    "npi":"1",

                    "number":"167772171"

                  },

                "ip_address":

                  {

                    "@incr_by":"1",

                    "_value":"10.1.1.10"

                  },

                "key":"0x000102030405060708090a0b0c0d0e00",

                "op":"0x63bfa50ee6523365ff14c1f45f88737e"

          }

      ]

  }