9 Replies Latest reply on Jan 7, 2016 8:58 AM by bsmith RSS
    pharlapur Explorer

    How to Convert JSON received from REST API to Bind to Object or variables

    Could you please help me with converting JSON received from REST API to Bind to Object or variables, so that they can be displayed on the Mashup.

     

    I have already tried with infotable, but it is now working as expected.

     

    Thanks,

    Prabhas

      • Re: How to Convert JSON received from REST API to Bind to Object or variables
        paic Collaborator

        If your input parameter is defined as JSON or if you are using a Service that retrieves JSON.

        Thingworx will treat it as an Object.

        So {MyValue:23} can be retrieved as JSONObjectVariable.MyValue

         

        If you are passing in a JSON Array, the node array is inserted then it becomes JSONObjectVariable.array[node].MyValue

         

        Note: Array is NOT inserted if it is a JSON Object in which one of the nodes is an array.

          • Re: How to Convert JSON received from REST API to Bind to Object or variables
            bsmith Apprentice

            Pai,

             

            This seems to be true when I test the service from ThingWorx Composer but not when testing from Chrome POSTMAN or CURL.

             

            For example:

             

            The simple JSON input is {"name":"Test Name"},

             

            I built a service as follows:

                 The input parameter is defined as type JSON with name variable1

                 In order to get the value for "name" the service references this as variable1.name.

             

            1. When I test using the Service's TEST button in Composer and pass the JSON {"name":"Test Name"} input variable - it works.

            2. When I test using Chrome POSTMAN and pass the JSON {"name":"Test Name"} as raw, Content-Type application/json - the variable1 is undefined.

            3. Also when I test using CURL from Linux and pass the JSON {"name":"Test Name"} - it fails with variable1 is undefined.

             

            Any ideas why the test would work within the ThingWorx Composer but not when called from outside?

             

            Thanks,