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

Pondering Automation: JSON and the Golden Web Service

2547
Views
10
Helpful
1
Comments
Cisco Employee

Hello all there out in automation land!!! I hope the year continues to be good for you and I hope you continue to develop exciting automations and use CPO for things only a few have dreamed of. This blog I wanted to talk a little about JSON, it's use in web services and some of the neat activities we have in Orchestrator to allow you to work with JSON and web serivces together. JSON (stands for JavaScript Object Notation) is a lightweight data-interface format that has become quite common for those developing web services based APIs. (http://json.org/) Those in the JSON world would argue it's easier to understand/use/read/etc for end users and computers. The people in charge of XML might argue with them, but that's another story for another time I suppose. In many of my previous cases I have seen and used XML as a message media for calling and receiving data back from web services. However about 2 months ago I was challenged with being able to automate things inside of our support ticketing system. This system uses JSON based web services, so it was off to learn another techology and adapt it to some great automations in Orchestrator. You can see a JSON example(and it's XML counterpart) at http://json.org/example.html for more reference.

 

Now that's great and all, but what can Orchestrator help us do with it? Well with the addition of a couple of activities - "Convert XML to JSON" and "Convert JSON to XML" it all becomes quite easy! In my development with Orchestrator I have found using XPATH queries and trying to stay in the XML format is best for ease of use and for the product in general. XPATH query is a wonderful tool for pulling data out of XML based messages and is highly useful(and near a requirement) for developing strong automations with web service calls. The great Orchestrator development team has almost made it trivial for you to be able to work with both XML and JSON based web services. The eaiest case is to receive JSON back from a web call and then pass it into a "Convert JSON to XML" activity. The output XML will be a nicely and neatly formated piece of XML that you can easily do an xpath query from. For example

 

JSON:

{

    "glossary": {

        "title": "example glossary",

        "GlossDiv": {

            "title": "S",

            "GlossList": {

                "GlossEntry": {

                    "ID": "SGML",

                    "SortAs": "SGML",

                    "GlossTerm": "Standard Generalized Markup Language",

                    "Acronym": "SGML",

                    "Abbrev": "ISO 8879:1986",

                    "GlossDef": {

                        "para": "A meta-markup language, used to create markup languages such as DocBook.",

                        "GlossSeeAlso": ["GML", "XML"]

                    },

                    "GlossSee": "markup"

                }

            }

        }

    }

}

 

Will convert to XML:

<glossary>

 

    <title>example glossary</title>

 

    <GlossDiv>

 

        <title>S</title>

 

        <GlossList>

 

            <GlossEntry>

 

                <ID>SGML</ID>

 

                <SortAs>SGML</SortAs>

                <GlossTerm>Standard Generalized Markup Language</GlossTerm>

 

                <Acronym>SGML</Acronym>

 

                <Abbrev>ISO 8879:1986</Abbrev>

 

                <GlossDef>

                    <para>A meta-markup language, used to create markup languages such as  DocBook.</para>

 

                    <GlossSeeAlso>GML</GlossSeeAlso>

 

                    <GlossSeeAlso>XML</GlossSeeAlso>

 

                </GlossDef>

 

                <GlossSee>markup</GlossSee>

 

            </GlossEntry>

 

        </GlossList>

 

    </GlossDiv>

 

</glossary>

 

 

(Sorry about the formatting)

Now doing XPATH queries on this xml is almost as trivial. If I want to pull out the Abbreviation, just XPATH Query it using "//Abbrev". (as an example). Before these activities you would have had to do string and regular expression work throughout a JSON response and that would have not been too pretty!

 

While this session is a short and sweet one, I could not go on without a video! So I have a quick (less than 10 minute) video on me using the JSON and XML conversion activities and running XPATH against it. (using the same demo JSON as above)

 

I hope after watching this you will feel confident in using JSON based web services in your automations. Please feel free to post any comments/questions/etc in the blog or send me an email.

 

Onto the video!!!

 

https://ciscosupport.webex.com/ciscosupport/lsr.php?RCID=e8689a9f43bb8bb1c039e08c9802550f

 

Shaun's Weekly Q/A

 

 

No questions this week! Hopefully we'll get some in to answer for next week!

 

Ever  week I will pick a handful of questions from you, the reading CPO  public, to answer in this part of the blog. Please post  comments/questions below. I will no longer be using the external e-mail  from previous blogs.

 

 

Please  also let me know if you like the format of this blog and what else you  would like to see/know about. Feel free to give any ideas as to future  blog posts, etc and I will be happy to post them. I hope to do more  how-tos, best practices, tips, tricks, and hopefully some interviews of  the important people behind the scenes of CPO.

 

 

WEEKLY  AUTOMATION BLOG DISCLAIMER: As always, this is a blog and my (Shaun  Roberts) thoughts on CPO, my thoughts on best practices, and my  experiences with the product and customers. The above views are in no  way representative of Cisco or any of it's partners, etc. None of these  views, etc are supported and this is not a place to find standard  product support. If you need standard product support please do so via  the current call in numbers on Cisco.com  or email tac@cisco.com

 

 

 

Thanks to all for reading and happy automating!

 

 

-Shaun Roberts

shaurobe@cisco.com

1 Comment
Cisco Employee

updated webex link. let me know if it does not work

CreatePlease to create content
Content for Community-Ad
July's Community Spotlight Awards