473,503 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simpleJSON pack binary data

Hi

I donno if this is the right place to ask for this question, anyway....

Is it possible to pack binary data into simplejson?

d={}
d['date'] = xxxxxx
d['name'] = xxxxxx
d['size'] = xxxxx

d['imageBinaryDataJpeg'] = jpegBinaryDataFromcStringIOStringIO

simplejson.dumps(d)

when i do this, it raises a UTF8 decode error, probably about the binary
image data

My question is, anyone will suggest a workaround to this error?
i really like to pack my raw image data into the JSON, so my other
programming script can read the array easily

Thanks
An K


Jul 22 '07 #1
1 4901
On Sat, 21 Jul 2007 19:13:22 -0700, Andrey wrote:
My question is, anyone will suggest a workaround to this error?
i really like to pack my raw image data into the JSON, so my other
programming script can read the array easily
JSON is a text format so you have to encode the binary data somehow. I'd
use base64. It's available as codec for `str.encode()`/`str.decode()`.

In [10]: '\x00\xff\xaa'
Out[10]: '\x00\xff\xaa'

In [11]: '\x00\xff\xaa'.encode('base64')
Out[11]: 'AP+q\n'

In [12]: _.decode('base64')
Out[12]: '\x00\xff\xaa'

Ciao,
Marc 'BlackJack' Rintsch
Jul 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1440
by: ashokbellur | last post by:
Hello, How do i pack different data types into a struct or an array. Examples would be helpful. Say i need to pack an unsigned char( 0xFF) and an long( 0xAAAAAAAA) into a single array? The...
1
8734
by: Niko Korhonen | last post by:
I'm currently in the process of programming a multimedia tagging library in standard C++. However, I've stumbled across one or two unclear issues while working with the library. First of all, is...
10
1563
by: Dan | last post by:
To all the gurus out there. I am writing a tool that receives binary data from a network device. The data arrives in a standard format which the vendor has documented, e.g. byte 0 is the format...
2
1858
by: Ron Snyder | last post by:
I'm attempting to use spamassassin 3.0 (beta) with an SQL backend, and have identified one performance gain so far that makes PostgreSQL a good (IMO) candidate for the backend. I need some advice...
6
2702
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios,...
0
2324
by: Wescotte | last post by:
I'm abit confused on how to work with binary data with an ODBC connection (My database is DB2 btw) Say I have a table like CREATE TABLE EJWLIB.BLOBTEST ( ID NUMERIC(5) NOT NULL, FILENAME...
3
6976
by: stockblaster | last post by:
Hello all.. Is it possible to convert a DataTable (i create the DataTable from a CSV file) into binary data and save it into an sql 2005 table (into binary field). After that I want to...
9
17950
by: thorley | last post by:
Greetings, since there was no reponse to my previous post about an existing FastCGI server in python, I've taken to writing my own. (which of course I'll share--*if* there's something to share ;) ...
8
13051
by: brainflakes.org | last post by:
Hi guys, I need to manipulate binary data (8 bit) stored in a 2 dimensional array. I've tried various methods (arrays, using a string filled with chr(0), using gd lib) and so far the fastest...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.