0

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.

1
  • Yes, you can, as a proof of concept check out jlinq: hugoware.net/Projects/jLinq Probably complete overkill hete, but just demonstrating anything's possible...just depends on how complex of a solution you need. Commented Jun 5, 2010 at 0:13

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

"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".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.