JSON Database

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

JSON Database

Post by Ark »

Hi guys, I wanted to know if it´s possible to save data like: (order: int, player: string, score: int) on a JSON file and also to retrieve that information later on. I know little or nothing about JSON, is it possible to retrieve data with javascript? or do I have to use AJAX?

Thanks for reading!
Orgullo Catracho
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: JSON Database

Post by Jackolantern »

MongoDB is essentially a JSON database, although there is a bit more to it than that. It cuts out a lot of the complexity to building, maintaining and querying a relational database such as MySQL.

As far as using JSON data in your applications, you can most definitely get the data with Javascript. That is the easiest language to work with JSON, since JSON is a subset of JS. You can use these methods to work with it:

To turn a JS object into a JSON string:

Code: Select all

var jsonString = JSON.stringify(jsObj);
And to turn it back into a Javascript object from the JSON string:

Code: Select all

var jsObject = JSON.parse(jsonString);
You can do that with AJAX, just in your own scripts, or wherever.
The indelible lord of tl;dr
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

Re: JSON Database

Post by Ark »

Thanks alot jack!
Orgullo Catracho
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: JSON Database

Post by Jackolantern »

Oh, I forgot to mention that the JSON global object used to deal with JSON is part of ECMAscript 5, and thus, is not available in older browsers. For compatibility, Douglas Crockford created a script that adds a JSON global object in browsers that don't already have it. Include the json2.js script on your page, then you can use the global JSON object anywhere.
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”