Unexpected token o in JSON - Python Dictionary to Google Sheets Rows

Have a simple python code that builds a dictionary, and need to create multiple sheet rows based on the number of items in the dictionary.
Pretty straightforward, but I get this error when testing the sheets module.
Unexpected token o in JSON at position 1
The code runs and returns results just fine


Anyone know where I went wrong?

Hello @giladl, first off, welcome to Pipedream!

May I ask what is the value for {{steps.python.$return_value}} in your workflow?

In the Row Values description, the value should be a string that can be parsed to a JSON. So I would expect the value is a string with the value [[ "Foo", 1, 2 ], ["Bar", 3, 4]]

It’s a dictionary

@giladl, could you JSON stringify that dictionary before returning it? This is an example

import json

# Data to be written
dict ={
"id": "04",
"name": "sunil",
"department": "HR"
}

# Serializing json
json_object = json.dumps(dict)

return json_object

Reference: How To Convert Python Dictionary To JSON? - GeeksforGeeks

yes, but that just turns it into a string, and then it doesn’t get recognized as separate rows to be imported

@giladl, I would suggest you to transform your dictionary into the nested array structure that is accepted by the Google sheet action in your Python code. I’m not really familiar with Python, but I think the logic is pretty straight forward:

  1. Create the outer array
  2. Then for each key - value in the dict, add a new array as an item into the outer array. The new array should have 2 elements, the first one is the key, and the second one is the value