views:

72

answers:

4

I'm retreiving a JSON string and parsing it with jQuery with $.getJSON.

After I get the data in a variable, can I add or remove rows? An example:

{"one": [{"sid":"1","name":"NAME 1"},{"sid":"2","name":"NAME 2"}],
 "two": [{"sid":"3","name":"NAME 3"}]}

Can I delete sid 1 from "one" and place it in "two"? How about sorting by sid? I'm using jQuery.

A: 

Sure, just evaluate the JSON document to JavaScript objects, and work on them.

k_b
+2  A: 

sure, you can do any of that, they are regular objects and arrays. You can sort arrays, remove their members, add members to other arrays, etc. I wouldn't use jquery stuff, just use basic array tools, such as splice and push and pop. splice() can do most anything: http://www.w3schools.com/jsref/jsref_splice.asp

Sorting is easy as well, just use sort() on the arrray.

rob
A: 

"After I get the data in a variable" - unless this variable is holding a string, which it probably isn't, it's not really JSON at that point - your question is a bit vague. JSON is an encoded form of data, usually used for sending information over a network or for storage on disk. It's a way to serialize information.

It could be used as the backend storage for a small "database". This kinda depends on your definition of "database" - if you're thinking generic relational database, yes, it can, inefficiently.

Your post however, makes it sound like you got some data and loaded it into a variable, which isn't really "using JSON as a database".

Thanatos
A: 

http://taffydb.com/

DBJDBJ