Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Object type of Node to json
I have Object type of Node like:

<Node id=1 labels={'First'} properties={'foo': 'foo', 'bar': 'bar'}>

I have tried to use like:

Response(dumps(res), mimetype="application/json")

But it throws an error:

TypeError: Object of type Node is not JSON serializable
please post some code that can be tried out.
That seems fairly self-explanatory to me, you have some class which the json module doesn't know how to serialize. So you need to come up with some way to bridge that gap, either by converting your object into a dictionary or by figuring out how the json module serializes stuff and implement whatever interface there is for it.
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Thanks everyone!

I have found a way to get dict list like:
for o in res:
  # dict_keys(['foo', 'bar'])
  # dict_values(['foo','bar'])
Now, please help me building a list and to convert it to json.


I'm not able to edit the reply - not sure how to do it.

I wanted to state that, I can grab as well:
print o.items()
# dict_items([('foo', 'bar'), ('foo', 'bar')])

My final expectation is to get like:

"id": 1,
"foo": "foo",
"bar": "bar"
} will get the id
I have to use dict(o.items)
micseydel likes this post

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  AttributeError: type object 'FunctionNode' has no attribute '_TestValidateFuncLabel__ binhduonggttn 0 78 Feb-19-2020, 11:29 AM
Last Post: binhduonggttn
  Type hinting - return type based on parameter micseydel 2 124 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Object of type set is not JSON serializable enigma619 5 752 Dec-19-2019, 03:30 PM
Last Post: enigma619
  type of object as a string Skaperen 1 180 Dec-02-2019, 08:01 AM
Last Post: midarq
  Object of type Scoreboard is not JSON serializable lsepolis123 9 2,916 Aug-13-2019, 11:22 AM
Last Post: lsepolis123
  Object and type class Uchikago 2 259 Jul-28-2019, 10:35 AM
Last Post: DeaD_EyE
  circle node with horizontal line in python graphviz mandana 0 355 May-05-2019, 10:39 AM
Last Post: mandana
  TypeError: object of type 'NoneType' has no len() - what do it mean? leviathan54 4 2,663 Apr-20-2019, 12:04 PM
Last Post: leviathan54
  Getting error "Type error-a bytes-like object..." mrapple2020 1 2,096 Apr-06-2019, 06:37 PM
Last Post: mrapple2020
  Not Able To Delete First Node From Python Linked List ribena1980 8 667 Mar-05-2019, 03:14 PM
Last Post: ichabod801

Forum Jump:

Users browsing this thread: 1 Guest(s)