Enhanced Security Measures in Place:   To ensure a safer experience, we’ve implemented additional, temporary security measures for all users.

Get/modify nested JSON list value

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Get/modify nested JSON list value

L4 Transporter

Hello,

There's a list in json format named "domainUrlStatus":

 

{"domain1.com":               {

                               "url1.com": {

                                               "status": "up",

                                               "date": "date"

                                               },

                               "url2.com": {

                                               "status": "down",

                                               "date": "date"

                                               }

                                               }

"domain2.com":               {

                               "url3.com": {

                                               "status": "up",

                                               "date": "date"

                                               },

                               "url4.com": {

                                               "status": "down",

                                               "date": "date"

                                               }

                                               }

                               }

 

How can the values be reached(think about the "." in the urls)?

How can I add a new value like "url5.com" inside "domain1.com"?

How to modify one of the last values? (like status)

How to check if a domain exists in all the json?

Trying to avoid using own automations, only using tasks

4 REPLIES 4

L5 Sessionator

Hi @Josep,

 

You'll need to escape the dot. Example below.

${domain\.com.url1\.com.status}

 

Let me know if this works for you.

 Thanks for the reply,

so I should create a task that adds an "\" before the dot for each variable.

L5 Sessionator

Hi @Josep.,

 

Sorry I don't see any way to make changes to the keys. You might need to try different escape sequences, but I was unable to find one. Also, passing the "\" to the deleteContext automation seems to break it and creates a context context entry. 

 

You could try passing the entire object into a python automation, but Python's JSON library might throw a schema error. Could you let me know which automation or integration is creating this context entry?

Yes, I'd many problems. First calling directly a variable of the list(json), like "${list}.${domain\.com.url1\.com.status}", this does not work. I need to put the Json inside the context

Second, what you said, I couldnt make changes to the keys, it was a mess, I had to convert them and then put them inside, not possible. 

So finally, I made it work just doing an automation in python from zero.

 

Load json:

allJSON = demisto.executeCommand("getList", {"listName":"domainUrlStatus"})
data = json.loads(allJSON[0]['Contents'])

 

Obtain the status given a domain and an url:

status = data[domain][url]["status"]

 

Change the status:

data[domain][url]["status"] = newStatus

 

Save the change on the JSON:

demisto.executeCommand("setList",{"listName":"domainUrlStatus""listData":data})

 

 

It's a pity that something so simple can't be done with simple tasks.

 

 

 

 

  • 2424 Views
  • 4 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!