Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

U2 Dynamic Objects for JSON and XML

220 views

Published on

U2 Dynamic Objects (UDO) let you interact with JSON and XML as objects. This can be useful when dealing with these universal data formats. Whether you are consuming or creating Web services, or just simply need to work with JSON/XML, UDO will get you there more quickly and more reliably.

Published in: Software
  • Be the first to comment

  • Be the first to like this

U2 Dynamic Objects for JSON and XML

  1. 1. 1 U2 Dynamic Objects (UDO) for JSON and XML Michael Byrne, MultiValue Evangelist
  2. 2. 2 Abstract  U2 Dynamic Objects (UDO) let you interact with JSON and XML as objects. This can be useful when dealing with these universal data formats. Whether you are consuming or creating Web services, or just simply need to work with JSON/XML, UDO will get you there more quickly and more reliably. ©2015 Rocket Software, Inc. All Rights Reserved.
  3. 3. 3 Agenda What are JSON and XML? UDO availability, definition, and overview Examples • Consuming JSON Web Service • Consuming XML Web Service • Creating JSON • Creating XML • Consuming a complex JSON API (time permitting) ©2015 Rocket Software, Inc. All Rights Reserved.
  4. 4. 4 What is JSON JavaScript Object Notation Human readable text used to transmit data • Attribute-Value pairs • Open standard format • Language independent Easily read by many programming languages ©2015 Rocket Software, Inc. All Rights Reserved.
  5. 5. 5 JSON Example { "invoiceId": "10-ABC-2111", "customer": 8001, "items": [ { "itemId": 33, "price": 21.99 }, { "itemId": 76, "price": 129 } ] } ©2015 Rocket Software, Inc. All Rights Reserved.
  6. 6. 6 What is XML Markup language for encoding documents • Human-readable and machine-readable Standardized Mature Not specifically SOAP ©2015 Rocket Software, Inc. All Rights Reserved.
  7. 7. 7 XML Example <invoice> <invoiceId>10-ABC-2111</invoiceId> <customer>8001</customer> <items> <item><itemId>33</itemId><price>21.99</price></item> <item><itemId>76</itemId><price>129</price></item> </items> </invoice> ©2015 Rocket Software, Inc. All Rights Reserved.
  8. 8. 8 UDO Overview  Not persistent; in-memory only  Purely a data object; no method support  Dynamic; properties can be added/removed on the fly  No inheritance  Unlimited nesting levels  Can create objects from XML/JSON or can be serialized into XML/JSON ©2015 Rocket Software, Inc. All Rights Reserved. UDO Object { “location”:”Denver”, “address”:”123 Main St”, “phones”: [ “303-555-1212”, “720-555-3434” ] }
  9. 9. 9 UDO Availability ©2015 Rocket Software, Inc. All Rights Reserved. 11.2.0 (JSON/XML) UniVerse 7.3 (JSON) 8.1 (XML) UniData Included in database engine (no charge) Set of Basic functions to work with objects Based on JSON specification • XML is achieved via conversion from JSON to XML • May not always be able to get back original XML
  10. 10. 10 Benefits of an Object Interface Less error prone • Concatenation • Manual parsing Shorter development time Error handling ©2015 Rocket Software, Inc. All Rights Reserved.
  11. 11. 11 UDO Usage Overview ©2015 Rocket Software, Inc. All Rights Reserved. UDOCreate(UDO_OBJECT,{name}) UDO Object … Get/Set Properties… (UDOGetProperty/UDOSetProperty) … { “location”:”Denver”, “address”:”123 Main St”, “phones”: [ “303-555-1212”, “720-555-3434” ] } UDOFree({name}) $INCLUDE INCLUDES UDO.H
  12. 12. 12 UDO Value Types ©2015 Rocket Software, Inc. All Rights Reserved. UDO Object { “locationId”: 1001, “location”: ”Denver”, “valid”: true, “address”: ”123 Main St”, “phones”: [ “303-555-1212”, “720-555-3434” ], “nulltest”: null } Object Array Number String Boolean Null
  13. 13. 13 Parsing JSON
  14. 14. 14 Popular Google API Examples ©2015 Rocket Software, Inc. All Rights Reserved.
  15. 15. 15 Parsing JSON From Web Service Google Time Zone API https://maps.googleapis.com/maps/api/timezone/json • location=36.114647,-115.172813 (Las Vegas, NV) • timestamp={timestamp} • key={api_key} ©2015 Rocket Software, Inc. All Rights Reserved.
  16. 16. 16 Google Time Zone Response - JSON ©2015 Rocket Software, Inc. All Rights Reserved. { "dstOffset" : 3600, "rawOffset" : -28800, "status" : "OK", "timeZoneId" : "America/Los_Angeles", "timeZoneName" : "Pacific Daylight Time" }
  17. 17. 17 Get Time Zone Basic Program ©2015 Rocket Software, Inc. All Rights Reserved. Submit request via CallHTTP Google Time Zone API { "dstOffset" : 3600, "rawOffset" : -28800, "status" : "OK", "timeZoneId" : "America/Los_Angeles", "timeZoneName" : "Pacific Daylight Time" } Read into UDO object Parse Values Get Response (String)
  18. 18. 18 Parsing the JSON with UDO ©2015 Rocket Software, Inc. All Rights Reserved. UDOGetProperty(RESTMSG, "dstOffset", dstOffset, UDOTYPE) UDOGetProperty(RESTMSG, "rawOffset", rawOffset, UDOTYPE) UDOGetProperty(RESTMSG, "status", status, UDOTYPE) UDOGetProperty(RESTMSG, "timeZoneId", zoneId, UDOTYPE) UDOGetProperty(RESTMSG, "timeZoneName", zoneName, UDOTYPE) { "dstOffset" : 3600, "rawOffset" : -28800, "status" : "OK", "timeZoneId" : "America/Los_Angeles", "timeZoneName" : "Pacific Daylight Time" } UDORead(data, UDOFORMAT_JSON, RESTMSG)
  19. 19. 19 Parsing XML
  20. 20. 20 Parsing XML From Web Service Google Time Zone API Using same API, but specify XML response https://maps.googleapis.com/maps/api/timezone/xml • location=36.114647,-115.172813 (Las Vegas, NV) • timestamp={timestamp} • key={api_key} ©2015 Rocket Software, Inc. All Rights Reserved.
  21. 21. 21 Google Time Zone Response - XML <TimeZoneResponse> <status>OK</status> <raw_offset>-28800.0000000</raw_offset> <dst_offset>3600.0000000</dst_offset> <time_zone_id>America/Los_Angeles</time_zone_id> <time_zone_name>Pacific Daylight Time</time_zone_name> </TimeZoneResponse> ©2015 Rocket Software, Inc. All Rights Reserved. Note property names
  22. 22. 22 Parsing the XML with UDO ©2015 Rocket Software, Inc. All Rights Reserved. UDOGetProperty(RESTMSG, “status", dstStatus, UDOTYPE) UDOGetProperty(RESTMSG, "raw_offset", rawOffset, UDOTYPE) UDOGetProperty(RESTMSG, “dst_offset", dstOffset, UDOTYPE) UDOGetProperty(RESTMSG, "time_zone_id", zoneId, UDOTYPE) UDOGetProperty(RESTMSG, "time_zone_name", zoneName, UDOTYPE) <TimeZoneResponse> <status>OK</status> <raw_offset>-28800.0000000</raw_offset> <dst_offset>3600.0000000</dst_offset> <time_zone_id>America/Los_Angeles</time_zone_id> <time_zone_name>Pacific Daylight Time</time_zone_name> </TimeZoneResponse> UDORead(data, UDOFORMAT_XML, RESTMSG)
  23. 23. 23 Creating JSON
  24. 24. 24 { } Creating JSON { } { "subprop1": "detail1" } { "subprop1": "detail1", "subprop2": "detail2" } { "mainprop": 9876 } { "mainprop": 9876, "subobject": { "subprop1": "detail1", "subprop2": "detail2" } } ©2015 Rocket Software, Inc. All Rights Reserved.
  25. 25. 26 Creating JSON For REST Developer Tool U2 REST Tool supports JSON data type Build exact JSON in Basic to return if desired Could also parse incoming JSON ©2015 Rocket Software, Inc. All Rights Reserved.
  26. 26. 27 Creating XML
  27. 27. 28 Creating XML Remember, UDO is based on JSON specification Simple interface, limited functionality • No mixing attributes and elements • Once XML convert to UDO, may not always be able to convert back to original For full XML support, use XDOM Basic functions ©2015 Rocket Software, Inc. All Rights Reserved.
  28. 28. 29 Creating XML <configuration> <appSettings> <add key="AppKey" value="AE48CA1F" /> </appSettings> <system.web> <compilation debug="true" strict="true" /> </system.web> </configuration> ©2015 Rocket Software, Inc. All Rights Reserved.
  29. 29. 30 Also JSON ©2015 Rocket Software, Inc. All Rights Reserved. { "appSettings": { "add": { "key": "AppKey", "value": "AE48CA1F" } }, "system.web": { "compilation": { "debug": "true", "strict": "true" } } }
  30. 30. 31 Note Differences Between JSON and XML ©2015 Rocket Software, Inc. All Rights Reserved. <configuration> <appSettings> <add key="AppKey" value="AE48CA1F" /> </appSettings> <system.web> <compilation debug="true" strict="true" /> </system.web> </configuration> { "appSettings": { "add": { "key": "AppKey", "value": "AE48CA1F" } }, "system.web": { "compilation": { "debug": "true", "strict": "true" } } } JSON XML
  31. 31. 32 Complex JSON Parsing Example
  32. 32. 33 Weather Service ©2015 Rocket Software, Inc. All Rights Reserved.
  33. 33. 34 UDO.GETWEATHER ©2015 Rocket Software, Inc. All Rights Reserved. UDOGetProperty(RESTMSG, "forecast", forecast, UDOTYPE) UDOGetProperty(forecast, "simpleforecast", simple, UDOTYPE) UDOGetProperty(simple, "forecastday", arrDays, UDOTYPE) GETSTAT = UDO_SUCCESS i = 0 LOOP GETSTAT = UDOArrayGetNextItem(arrDays, W.UDO, W.TYPE) WHILE GETSTAT = UDO_SUCCESS DO i = i + 1 UDOGetProperty(W.UDO, "date", UDO.DATE, UDOTYPE) UDOGetProperty(UDO.DATE, "monthname", F.MONTH, UDOTYPE) UDOGetProperty(UDO.DATE, "day", F.DAY, UDOTYPE) UDOGetProperty(UDO.DATE, "year", F.YEAR, UDOTYPE) UDOGetProperty(W.UDO, "high", UDO.HIGH, UDOTYPE) UDOGetProperty(UDO.HIGH, "fahrenheit", HF, UDOTYPE) UDOGetProperty(W.UDO, "low", UDO.LOW, UDOTYPE) UDOGetProperty(UDO.LOW, "fahrenheit", LF, UDOTYPE) UDOGetProperty(W.UDO, "conditions", CONDITIONS, UDOTYPE) REPEAT
  34. 34. 35 Additional Resources  https://en.wikipedia.org/wiki/JSON  https://en.wikipedia.org/wiki/XML  https://developers.google.com/maps/documentation/timezone/intro  http://www.rocketsoftware.com/resource/u2-technical-documentation • Find the Basic Extensions Guide for your data server version ©2015 Rocket Software, Inc. All Rights Reserved.
  35. 35. 36 Next Steps Download the UDO documentation found in Basic Extensions manual Get sample code from GitHub ©2015 Rocket Software, Inc. All Rights Reserved.
  36. 36. 37 Summary UDO can be used to parse or create JSON/XML Based on the JSON specification, XML mileage may vary Could be paired with the RESTful Web Services tool ©2015 Rocket Software, Inc. All Rights Reserved.
  37. 37. 38 Disclaimer THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILE EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN ADDITION, THIS INFORMATION IS BASED ON ROCKET SOFTWARE’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY ROCKET SOFTWAREWITHOUT NOTICE. ROCKET SOFTWARE SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: • CREATING ANY WARRANTY OR REPRESENTATION FROM ROCKET SOFTWARE(OR ITS AFFILIATES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS); OR • ALTERING THE TERMS AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT GOVERNING THE USE OF ROCKET SOFTWARE. ©2015 Rocket Software, Inc. All Rights Reserved.
  38. 38. 39 Trademarks and Acknowledgements The trademarks and service marks identified in the following list are the exclusive properties of Rocket Software, Inc. and its subsidiaries (collectively, “Rocket Software”). These marks are registered with the U.S. Patent and Trademark Office, and may be registered or pending registration in other countries. Not all trademarks owned by Rocket Software are listed. The absence of a mark from this page neither constitutes a waiver of any intellectual property rights that Rocket Software has established in its marks nor means that Rocket Software is not owner of any such marks. Aldon, CorVu, Dynamic Connect, D3, FlashConnect, Pick, mvBase, MvEnterprise, NetCure, Rocket, SystemBuilder, U2, U2 Web Development Environment, UniData, UniVerse, and wIntegrate Other company, product, and service names mentioned herein may be trademarks or service marks of others. ©2015 Rocket Software, Inc. All Rights Reserved.
  39. 39. 40

×