Opened 10 years ago

Closed 8 years ago

#2251 closed enhancement (fixed)

[patch] JSON support

Reported by: okamototk Owned by: Alec Thomas
Priority: normal Component: XmlRpcPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description (last modified by Steffen Pingel)


If XmlRpcPlugin support JSON protocol, it's fine to support Ajax function. I develop the patch with Shibuya.trac project which is the group by Japanese users and developers.

Please apply our patch to support json.


Takashi Okamoto


Attachments (2)

jsonsupport.patch (14.2 KB) - added by okamototk 10 years ago.
Patch to support JSON (25.2 KB) - added by okamototk 10 years ago.
sample for json support

Download all attachments as: .zip

Change History (9)

Changed 10 years ago by okamototk

Attachment: jsonsupport.patch added

Patch to support JSON

Changed 10 years ago by okamototk

Attachment: added

sample for json support

comment:1 Changed 10 years ago by anonymous

Component: TracHacksXmlRpcPlugin

comment:2 Changed 9 years ago by Gunnar Thielebein

Type: enhancementdefect

I tried your patch with the recent releases of Trac (0.11dev-r7092) and xmlrpc (TracXMLRPC-1.0.0-py2.5.egg) and your getticket example.

I get the following error:

2008-05-30 00:00:56,759 Trac[main] DEBUG: Dispatching <Request "POST u'/json/ticket.get'">
2008-05-30 00:00:56,779 Trac[web_ui] DEBUG: /json/ticket.get matches True
2008-05-30 00:00:56,821 Trac[svn_fs] DEBUG: Subversion bindings imported
2008-05-30 00:00:56,829 Trac[api] DEBUG: action controllers for ticket workflow: ['ConfigurableTicketWorkflow']
2008-05-30 00:00:56,861 Trac[web_ui] ERROR: Cannot write in JSON: <DateTime '20080122T19:50:46' at 16f57a0>
2008-05-30 00:00:56,862 Trac[web_ui] ERROR: Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/tracrpc/", line 73, in process_request
    self._send_response(req, json.write(result[0]).encode('utf-8'), content_type)
  File "build/bdist.linux-x86_64/egg/tracrpc/", line 935, in write
    return JsonWriter().write(obj, escaped_forward_slash)
  File "build/bdist.linux-x86_64/egg/tracrpc/", line 883, in write
  File "build/bdist.linux-x86_64/egg/tracrpc/", line 903, in _write
  File "build/bdist.linux-x86_64/egg/tracrpc/", line 932, in _write
    raise WriteException, "Cannot write in JSON: %s" % repr(obj)
WriteException: Cannot write in JSON: <DateTime '20080122T19:50:46' at 16f57a0>

2008-05-30 00:00:57,047 Trac[main] DEBUG: 13 unreachable objects found.

comment:3 Changed 9 years ago by Gunnar Thielebein

Type: defectenhancement

comment:4 Changed 9 years ago by Alec Thomas

Status: newassigned

This patch shouldn't include its own JSON parser, just add one as a dependency to the Is there some other reason that something like simplejson can't be used?

Otherwise looks pretty good to me.

comment:5 Changed 9 years ago by Gunnar Thielebein

I removed and installed the hardy package python-json. The error of last comment remains. athomas did this patch works for your config ootb? can you post your version of trac/json/xmlrpcplugin? How would I do replace json / simplejson?

comment:6 Changed 8 years ago by Steffen Pingel

Description: modified (diff)
Summary: [PATCH] JSON support[patch] JSON support

comment:7 Changed 8 years ago by Odd Simon Simonsen

Resolution: fixed
Status: assignedclosed

(In [6065]) XmlRpcPlugin: JSON-RPC support. It requires either Python 2.6 (part of standard lib, but untested by me), or easy_install simplejson for 2.4/2.5 (tested).

Building on recent changes with types, all methods are already protocol and type agnostic and work unchanged. Summary of important changes:

  • With a lot of recent changes to the core of the plugin, I wanted this change to be as unobtrusive as possible. Therefore it just switches on Content-Type header in main handler, leaving XML-RPC and JSON-RPC to doing their own things. At some stage the protocol code will be abstracted using extension-points so that adding protocol handlers can be done more cleanly - including from other plugins.
  • It tries to conform quite closely to the various versions, drafts and ongoing discussions for the JSON-RPC specification. However, that work is somewhat in flux, so changes may be needed later.
  • JSON-RPC has no notion of types outside the standard Javascript types that are easily converted to very similar Python types. In order to support 'datetime' and 'binary' at any level in arguments (like a 'due' field in attributes for milestone update), some form of type-hint was needed: {"__jsonclass__": ["binary", "<base64-encoded>"]} is how to specify a binary value (similar structure for 'datetime'). See the new HTML documentation on /xmlrpc or /jsonrpc for details. Custom encoder + decoder handles all conversions.
  • For the first time in the history of the plugin, the new feature comes complete with unittests that actually shows and verifies that it works. Not bad :-)

Bumped version.

Closes #2251. Closes #3241. Please create new tickets for issues that follows this change.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Alec Thomas.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.