[rabbitmq-discuss] JSON Data to be send between Java Producer and Python Consumer

Gavin M. Roy gmr at meetme.com
Sat Apr 20 19:28:39 BST 2013


To add to this the consumer probably needs to use json.loads(value, ensure_ascii=False) (not the default value for ensure_ascii) to allow it to decode UTF-8 in a JSON string.  


On Saturday, April 20, 2013 at 7:03 AM, Laing, Michael P. wrote:

> Hi Arun,
>  
> Probably you are sending unicode in your json from the java side.
>  
> On the python side it is probably complaining about not being able to decode using the ascii codec… is that correct? This would mean that the received data is encoded in another scheme, probably utf8.
>  
> Really guessing here but… you could first try forcing the java side to only send ascii, stripping out or transforming any non-ascii characters. This would tell you if you are on the right track. Then you could try to really fix the problem by getting the java side to encode unicode as ascii rather than utf8 (you will see '\unnnn' strings in the output). I don't know how to do that.
>  
> I usually handle problems like this on the python side by decoding json using the utf8 codec, but that is not an option open to you.
>  
> Michael
>  
> From: Arun Viswanath <arun.viswanath at gmail.com (mailto:arun.viswanath at gmail.com)>
> Reply-To: rabbitmq <rabbitmq-discuss at lists.rabbitmq.com (mailto:rabbitmq-discuss at lists.rabbitmq.com)>
> Date: Saturday, April 20, 2013 2:38 AM
> To: "rabbitmq-discuss at googlegroups.com (mailto:rabbitmq-discuss at googlegroups.com)" <rabbitmq-discuss at googlegroups.com (mailto:rabbitmq-discuss at googlegroups.com)>
> Subject: [rabbitmq-discuss] JSON Data to be send between Java Producer and Python Consumer
>  
> Hi,  
>  
> I'm facing an issue while sending the JSON data between Java Producer and  Python Consumer.  
>  
> I doing the following serialization in my Java Producer for my JSON data and placing the serialize data in the Queue  
>  
> Java Code:  
> import org.json.simple.JSONObject;  
> import org.json.simple.parser.JSONParser;  
>  
>  
> // Reading the JSON content from the file and making it an JSONObject  
> JSONObject serviceObj = (JSONObject) parser.parse(new FileReader("C:\\Msg2.json"));  
>  
> String jsonText = new flexjson.JSONSerializer().serialize(jsonObj);  
>  
> channel.basicPublish("", CONDUCTOR_QUEUE_NAME, null, jsonText .getBytes());
>  
> -----------------  
> My python consumer successfully takes the data from the Queue but it is not able to process it.  
> Python consumer is expected to deserialize the json message read from the Queue to Python dictionary but the data got after deserialize is python unicode type.  
>  
> My python consumer is third party code so I can't change my consumer side.  
> I'm not sure whether I'm doing the correct stuff in my Java producer.  
>  
> Any help to resolve this issue will be appreciated.  
>  
> Thanks In Advance,  
> Arun V  
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com (mailto:rabbitmq-discuss at lists.rabbitmq.com)
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>  
>  


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130420/86aa606a/attachment.htm>


More information about the rabbitmq-discuss mailing list