Gilles De Mey
Gilles De Mey

Reputation: 317

Best way to store JSON response?

I was wondering what would be the best way to store JSON/XML responses. I'm currently building an application that supports heavily on the SoundCloud API to fetch songs/playlists etc.

Here are some ideas I've come up with.

  1. Storing the results in a Relational Database and then using PHP to convert them to classes to make easy use of them throughout my application.
  2. Doing the above, only this time using my framework's built-in ORM.
  3. Using a Document-Oriented Database. (ie. MongoDB, couchDB, ...)
  4. Storing the JSON responses in a cache. (using my framework's cache classes)

Can anyone care to shed some light on some of the advantages/disadvantages of using any of these methods?

Which one do you prefer?

Upvotes: 3

Views: 3701

Answers (3)

sosandstrom
sosandstrom

Reputation: 51

If you can tolerate hosting your music and playlist data on Google's AppEngine, Ubud-db can be something for you: https://bitbucket.org/f94os/ubud-db/wiki

Ubud-db is a document store on AppEngine with a REST-JSON API. Spring/Jackson maps from JSON to a Map, and then Ubud's service maps from the Map to Entity, persisted by the Datastore.

The REST-JSON API makes it easy to integrate with a website using AJAX to access and display dynamic data.

Upvotes: 1

DarthVader
DarthVader

Reputation: 55092

If you have a solid schema, that you wont think it will change, you might want to use relational database. You will need to parse the json and make objects out of the JSON response and using your framework you can persist it to database.

If you think your schema will change use NoSQL.

It also depends what will you do with this data. Are you going to search the nodes within JSON? You can also do a object to mongo mapping, you can either parse the JSON and store it as an object or you can store the JSON the way it is.

Nice thing about NOSQL is that they support JSON pretty well in which they use BSON (Binary JSON).

In terms of cache, IME, it should be used only for lookups, and actually, you cant search the cache. It s just for getting objects faster than going to database and getting it.

Take a look at this:

http://www.mongodb.org/display/DOCS/Inserting#Inserting-JSON

Upvotes: 2

endyourif
endyourif

Reputation: 2202

If I need keep the data for longer than a cache provider, I would store them in a database as-is and then just json_decode them when I retrieve them from the DB. If it's just temporary storage, cache is a great idea, still leaving it encoded as json to reduce the size.

Upvotes: 0

Related Questions