cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

How to read in a complex json for mashups?

beck.smith
1-Visitor

How to read in a complex json for mashups?

Can someone give me pointer to the documentation, examples, and preferred methods on how to input complex json from an external source.

 

Note: We are not allowed to reach into the provider for the JSON so ContentLoader functions are not an option, the provider will have to push it to the ThingWorx platform.

 

That being the case, I tried using RESTFul API with POST with JSON payload and invoking a service with that JSON as the input and then parsing through the JSON.

 

Having little success (but great frustration) in getting the JSON input into the service.

 

References on the Developer Community (Pai Chung Jul 20, 2015 "How to Convert JSON received from REST API to Bind to Object or Variable") suggests: “If you 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:123} can be retrieved as JSONObjectVariable.MyValue”

 

I defined the input as JSON however, this does not work (or I can’t get it to work) and some guidance would be greatly appreciated.

 

I have seen several threads which discuss in and around the subject in various degrees.

For example, I need to input the following json and act upon it (i.e display mashups)

{
    "server": {
        "disk": {
            "used": "1240M",                        
            "capacity": "1416M"                    
        },
        "ethernet": {
            "address": "192.168.x.xxx",
            "mac": "00:xx:yy:zz:ww:99"             
        },                                           
        "cpu": {
            "average": "0.04",                     
            "uptime": "19 days, 11:16",            
            "load": "0.24",                        
            "temp": "76.8"                         
        },
        "location": "Unknown",                     
        "name": "MyLinux",
        "version": "6.5",                        
}
}

Thanks,

4 REPLIES 4

Beck, you have an errant comma at the end of your version line.  Removing that should allow it to parse properly.

Thanks for the reply.  I corrected the JSON and subsequently used a much simpler example to test.  Even with the simple and correct JSON passing the payload in with a PUT in the content/body does not work.

Check out PTC Case 12850642  that I opened.  There *may* (not confirmed yet)  be a bug ingesting POST data in content/body which is the root of the issue I am experiencing. 

Am awaiting feedback from support on confirmation of that and guidance.

Thanks

 

You can use tools like http://codebeautify.org/jsonviewer and http://jsonformatter.org. These tool will helps to analyse, validate, convert JSON data.

Thanks for the reply and pointer to tools.  I corrected the JSON example in my post (trailing comma) and subsequently used a much simpler example to test.

The tools you recommend will certainly come in handy - appreciate the pointers.

Thanks,

Announcements


Top Tags