1

I have this query which I got from a monday.com website. I am trying to get the column values for the respected board and trying to put those values into a python dictionary so that I can iterate over with some conditions later on and update the values back to the website. As per the instructions given by the API (Monday.com and GraphQL) I ran this query to get the column values of the board but I am failing to convert it into a python dictionary. Please help! This is the query code I wrote on Graph QL API playground:

  boards(ids: 1348913462) {
    items(limit: 50) {
      id
      column_values(ids: "pratica_cliente") {
        value
      }
    }
  }}

Now in order to convert it to a dictionary, i ran the following code:

contents=[]
try:
    with open("./r.json", 'r') as f:
        contents =json.load(r)
except Exception as e:
    print(e)

print(contents[:]["value"])

li = [item.get('column_values') for item in contents]
print(li)

The error I am getting is:

[Errno 2] No such file or directory: './r.json' Traceback (most recent call last): line 31, in print(contents[:]["value"]) TypeError: list indices must be integers or slices, not str

It is returning me the whole JSON file as output but I intend for it to be a python dictionary like:

dict = {id:value,
        id2:value2....and so on}

And yes I searched a lot on stack and google and other places so some of the codes are also taken from few places.

1 Answers1

1

This won't work because you don't have a variable "r" to json.load.

    with open("./r.json", 'r') as f:
        contents =json.load(r)

and apparently "./r.json" isn't a file. So contents will always be []

Then you try to access contents which is a list by using a string.

This is why you see those errors. Pretty self-explanatory.

drice304
  • 96
  • 1
  • 3