7 Replies Latest reply on Jan 15, 2018 10:28 PM by anderswi RSS
    anderswi Newbie

    FromJSON() usage



    I need to convert a JSON-structure loaded from an external API into an InfoTable that I return from my service. Now I'm creating the InfoTable from a DataShape and manually adding rows in a for each loop, which works well. Then I found this method which seem convenient:



    I tried it but got complaints about a missing "dataShape" field in the JSON structure... The error makes sense but I can't figure out the right syntax for communicating which DataShape to use. The method documentation does not give any clues.


    Can anybody share some example code that uses this method? Preferably in conjunction with LoadJSON :)


    Kind Regards,


      • FromJSON() usage
        adam Creator

        Hi Anders,


        Indeed. FromJSON() seems convenient, but it doesn't do what you expect. That is to say, it doesn't do what you and I would like it to do ;-)

        For FromJSON() to execute successfully, the Data Shape of the info table you wish to create must be specified in the JSON object (not just the name, but the entire structure (ie. field definitions)). The use case for this Service is limited – iterating through the JSON object and adding rows to an info table is the way to go.



        • FromJSON() usage
          anderswi Newbie

          Thanks for explaining it Adam. A deceptive service indeed! :)

          • Re: FromJSON() usage
            pierregar Explorer

            Hello Anders,


            How do you call the external REST services ?

            I have to make the same the thing but I did not succeed .


            I have trid the LoadJSON method .... but it is not working ..


            Thanks and regards,

            • Re: FromJSON() usage
              sv Apprentice


              I am facing with the same issue. I am not able to resolve it. Can some one help me with that


              The code that i use :

              var params = {




              // result: JSON

              var Json = Resources["ContentLoaderFunctions"].GetJSON(params);

              var Infotable=Resources["InfoTableFunctions"].FromJSON({json:Json});

              var testString=Infotable.test;

              var result=testString.split("|");









              This code was working fine with Thingworx composer 6. But now it showing this error "Wrapped org.json.JSONException: JSONObject["dataShape"] not found. Cause: JSONObject["dataShape"] not found."

                • Re: FromJSON() usage
                  ianban Creator



                  As per Adam's reply earlier in the thread, FromJSON doesn't do what you think it does. It only works if the JSON is already in the format of a ThingWorx InfoTable with an array called (I think)  "fields" that defines all of the properties.


                  Simpler not to use this method and just parse the JSON that you're getting back.