473,657 Members | 2,418 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['imageBinaryDat aJpeg'] = jpegBinaryDataF romcStringIOStr ingIO

simplejson.dump s(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 4911
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('base6 4')
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
1445
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 reason i need to do this is send a packet over a network. Thanks,
1
8751
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 it safe to store binary data in std::string? This question rose from my implementation with APEv2 tags. An APEv2 tag's field value can contain either UTF encoded text or binary data. I've decided to use std::string to represent the field value....
10
1575
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 version, 1-4 are integers between 0 and 255, etc. At this point I just want to format the data into something that can be read by humans and write it to the console. I have seen some other examples of how people acomplish this but none in visual...
2
1884
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 though on another aspect-- instead of storing each token as text in the database, the token is being sha1()'d and then possibly pack()'d. That's all just background for my real question-- is there anything in the standards (or elsewhere) that...
6
2714
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, every now and then the client would timeout and have to re-initiate the request... TIA!
0
2338
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 VARCHAR(128) NOT NULL, BINARY BLOB(2M) ) Now I (I assume this is the correct method) insert data in the
3
6991
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 have the ability to add a row to the beginning of the to the binary data..
9
17987
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 ;) My problem now, is that I need to send certain binary data over a socket. That is, I want to make some bytes, and stuff them in a TCP packet, send them down the pipe, and then listen for a response. socket.send, as best I can tell, will only...
8
13058
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 way I've found is to actually create an 8-bit image in GD and use imagecolorat and imagesetpixel to read and write the data.
0
8315
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5633
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4164
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.