2 Replies · Latest reply on Nov 9, 2017 10:50 AM by lnz001

    Ask the Experts: Understanding JSON - TechNow Ep. 37

      expert-logo-2.png

      Constructing easy integrations to other systems is a big part of what makes ServiceNow such a wonderful application development platform. Sometimes the challenge lies in figuring out exactly what you have been given and how to apply it in ServiceNow. In this episode, the TechNow crew will guide you through one of the most common data exchange formats - JSON. Even though the results from your remote system are text, it may be difficult to understand it and get access to the specific property or value in JavaScript. As always, the team starts with some easy examples to help you understand the fundamentals and build more complex scenarios to help you interpret and access complex data objects. Community quick tip: Avoiding pitfalls with platform objects.

       

      Originally aired April 13, 2017 12:00PM PDT 
      (Be sure to change your YouTube Setting to 720HD)

       

      Ask your questions below on this discussion page.

      And Please Let our Experts know how they've helped! Comment Below!

      Like, Share, Mark Helpful.

       

      Please Like and Share!  Find More Events on the Community!

       


      Featured Experts

       

      Chuck Tomasi is a Platform Architect for ServiceNow.  He is a computer science major with over 30 years of IT experience. As a former ServiceNow customer, Chuck won the first Innovation of the Year Award at Knowledge 10. Since joining ServiceNow in 2010 as a Technical Consultant, he has done many large scale ITSM implementations and custom applications, acted as an adjunct instructor for Education Services, created and lead the Technical Best Practices program, and co-hosts the ServiceNow series “TechNow”.

       

      Dave Slusher has been developing software for 20 years for companies such as Intel, Orbitz, Dell Secureworks and many startups lost to history. He has been with ServiceNow for two years, first in Expert Services and now as the Developer Evangelist for the developer community and portal. He earned his BS from Georgia Tech and his MS in Computer Science from the University of Louisiana - Lafayette.

       

       

      Kreg Steppe is a Senior Curriculum Developer within ServiceNow developing and supporting cloud training infrastructure. He specializes in developing integration solutions, automating repeatable processes and Cloud Management in ITOM. Kreg’s prior experience includes operating his own ISP, developing web applications in PHP, network integration, managing network support, Application Development on cloud based networks, DNS and email server maintenance. He is a Linux enthusiast and enjoys Photography.

        • Re: Ask the Experts: Understanding JSON - TechNow Ep. 37
          Chuck Tomasi

          Here is the code and config for TechNow ep 37.

           

          Quick Tip Repository

           

          Demo 1:

          // Simple JavaScript object with property
          var person = { "name": “Chuck"};
          gs.info(person.name);
          

           

          Demo 2:

          // JavaScript Object with 2 properties
          
          var person = {
              "name": "Chuck",
              "age" : 52
          };
          gs.info(person.name + ' is ' + person.age);
          

           

          Demo 3:

          // Simple stringify example
          var person = {
              "name": "Chuck",
              "age" : 52
          };
          
          person.children  = [];
          var child1 = {"name" : "Julie", "age" : 23};
          var child2 = {"name" : "Liisa", "age" : 21};
          person.children.push(child1);
          person.children.push(child2);
          
          gs.info(JSON.stringify(person));
          

           

          Demo 4:

          // Accessing Objects
          var personString = '{ "name": "Chuck", "age" : 52, "children" : [ {"name" : "Julie", "age" : 23}, {"name" : "Liisa", "age" : 21} ] }';
          var person = JSON.parse(personString);
          
          gs.info('person.name=' + person.name);
          
          if (person.children) {
            for (var i = 0; i < person.children.length; i++) {
              gs.info('Child ' + i + '=' + person.children[i].name);
            }
          }
          

           

          Demo 5:

          // Using a response back from an integration
          try { 
           var r = new sn_ws.RESTMessageV2();
           r.setHttpMethod('GET');
           r.setEndpoint('https://democt1.service-now.com/api/x_66238_weather/forecast/2017-04-13');
          
           var response = r.execute();
           var responseBody = response.getBody();
           gs.info('responseBody=' + responseBody);
           gs.info('Hi Temp=' + responseBody.result.temp.hi);
           var httpStatus = response.getStatusCode();
          } catch(ex) {
           var message = ex.getMessage();
          }
          

           

          Demo 6:

          // Making complex objects more readible
          // using JSON.stringify(obj, replacer, space)
          
          try { 
           var r = new sn_ws.RESTMessageV2();
           r.setHttpMethod('GET');
           r.setEndpoint('https://en.wikipedia.org/api/rest_v1/feed/onthisday/events/04/13');
          
           var response = r.execute();
           var responseBody = response.getBody();
           gs.info('responseBody=' + responseBody);
          
          // var doc = JSON.parse(responseBody); 
          // gs.info(JSON.stringify(doc, null, 4));
          
           var httpStatus = response.getStatusCode();
          } catch(ex) {
           var message = ex.getMessage();
          }
          
          1 of 1 people found this helpful

          --Chuck Tomasi
          --Sr. Technical Product Marketing Mgr, Now Platform
          --Join me on the Community live stream (most) weekdays at 8:00AM ET
          --https://youtube.com/user/servicenowcommunity

          • Re: Ask the Experts: Understanding JSON - TechNow Ep. 37
            lnz001

            Did you participate?

            We'd love to hear your feedback on this event!

            Please Take the Survey - and tell us what you think!

             

            oh and

            Find More Events on the Community!


            Lisa Latour
            Community Engagement Manager