JsonOutputHandler Doesn't Pass Keyword Args to json.dumps() #385

Closed
dbrady-work opened this Issue Jul 7, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@dbrady-work

I'm trying to render some JSON that has some Decimal values and I get the error "Decimal('9.09') is not JSON serializable". I would like to be able to call something like self.app.render(x, cls=DecimalEncoder), where I can use the keyword arguments found in the JSON python library. Is this possible?

Thanks

@derks derks added the stable/2.10.x label Jul 7, 2016

@derks derks added this to the 2.10.0 Stable milestone Jul 7, 2016

@derks derks self-assigned this Jul 7, 2016

@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Jul 7, 2016

Member

This is actually a bug in JsonOutputHandler ... the render() function takes **kwargs but doesn't do anything with them... but it should be passing them down to json.dumps() ... which should fix your issue. Give me a few and I'll try and work it in quickly.

Member

derks commented Jul 7, 2016

This is actually a bug in JsonOutputHandler ... the render() function takes **kwargs but doesn't do anything with them... but it should be passing them down to json.dumps() ... which should fix your issue. Give me a few and I'll try and work it in quickly.

@akhilman

This comment has been minimized.

Show comment
Hide comment
@akhilman

akhilman Jul 7, 2016

Contributor

This problem could be solved by pre_render hook which converts decimals to floats or strings.
I had same problem but with numpy.float64.

Contributor

akhilman commented Jul 7, 2016

This problem could be solved by pre_render hook which converts decimals to floats or strings.
I had same problem but with numpy.float64.

@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Jul 7, 2016

Member

Right, good call... that's exactly what the pre_render hook is intended for... altering the data before the output handler renders it.

Member

derks commented Jul 7, 2016

Right, good call... that's exactly what the pre_render hook is intended for... altering the data before the output handler renders it.

@derks derks changed the title from Including keyword arguments with JSON in ext_json.py to JsonOutputHandler Doesn't Pass Keyword Args to json.dumps() Jul 7, 2016

derks added a commit that referenced this issue Jul 7, 2016

@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Jul 7, 2016

Member

@dbrady-work can you try cement/master and see if the self.app.render(x, cls=DecimalEncoder) idea works for you? The **kwargs are now being passed down to json.dumps().

Member

derks commented Jul 7, 2016

@dbrady-work can you try cement/master and see if the self.app.render(x, cls=DecimalEncoder) idea works for you? The **kwargs are now being passed down to json.dumps().

@dbrady-work

This comment has been minimized.

Show comment
Hide comment
@dbrady-work

dbrady-work Jul 7, 2016

@derks It works!!!! Thank you so much.

@derks It works!!!! Thank you so much.

@dbrady-work dbrady-work closed this Jul 7, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment