'How to convert berkeley db files into CSV/JSON?
I have some files (__db.001, ...),
I would like to convert this database into JSON/CSV...
Does BerkeleyDb support such features or Is there any tools ?
I know this is a tool called db_dump But I don't think it can convert database files into Json or CSV...
Solution 1:[1]
Berkeley DB's data records are stored in a binary format defined by the particular application that uses it. There's no way to universally dump records in a way like you would with a traditional SQL database.
If you know how the keys and data are formatted by the application, then you can use the db_dump
utility to generate a hexadecimal dump of the database. Then, you can parse that and break the records down into something that you can put in JSON.
For example, you might have an application that stored the contents of your shopping cart in each record: milk, eggs, and bread. In JSON, that would break down into something like { "milk": 5, "eggs": 24, "bread": 1 }
.
But in BDB, it might be something like the following C struct:
struct {
uint32_t milk;
uint32_t eggs;
uint32_t bread;
} record;
Each record would be 12 bytes long. The first four are milk, perhaps in little-endian format. The next four are eggs. And, so on. When you use db_dump
on this, it'll just output 12 hexadecimal bytes. It's on you to parse what those bytes mean.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mike Andrews |