logo

NJP

How to read JSON data? | Javascript functions | ServiceNow

Import · Jul 06, 2022 · video

hi everyone in this video i am going to talk about another javascript function this is also very very important when we are dealing with data across different applications or when we are dealing with data to and so let's take a look about how a particular function works and i'm going to declare a javascript object first and this is how we declare an object in javascript first of all i need to assign certain parameters to this object let me declare two of them oh so now my javascript function contains two different parameters and if i have to check what this object contains uh let's say i do not have the luxury to declare these variables that will come this data is coming from somewhere else and i want to check what exactly this object contains so i can simply pass that object in this alert and if i click which doesn't make much sense to me because i won't be able to see the data i just know that okay this is of type object but not at all because i can't see the data so if i have to see the data i will use a function called json.strength now this is my data in the string format what if after receiving the data in the same format i want to pass it back to the object summit how can i do that so let me first save this information in another variable so now this will contain the data in the same format as expected and if i want to let it pass it back to the object form then i can simply do it by using json. let's see if it is working fine or not exactly from the run now so this is the expected result for the first alert there in i should be receiving a string and if i click on ok again i'm receiving this in the object format again because first i am doing simplify to see what my object contains and let's say i already have a string i declared a thing now i want to convert that to an object so i can simply use json.paths function so we are discussing two different functions here first one is json.senior and the second one is statement.parse first function converts an object to a format and the second one simply converts it back to the object format also let's see how i can read a particular data from this object let me add one more color let's see i want to uh if i want and i will be able to see the value of that particular parameter if i click on one i get the actual value and the most common use cases of using this is when you're dealing with integrations wherein you're getting data in the uh json format from the request so by default it is in the object format and if i have to read that data i will be doing object name dot parameter name let's say i'm getting incident data in one of my integrations and i have to read the sort description from that data so the object which i am receiving my data in object name dot short description will give me the short description from that just an object and the other use this would be when you're sending data back from your script include to your client script wherein you are you are making use of glide ajax and you want to send an object back to your client script so you do not have a software we do not have the luxury to send directly and from scripting here to the client so what we do is we convert that object within using json.stringify and then we send that object to client side so these are the two most common use cases of defender string and json.com so thank you for watching

View original source

https://www.youtube.com/watch?v=hIZ9r5klSxI