Appropriate use for JSON?

Great site! I have a question that I have not seen.

I'm very new to this, I didn't know there was JSON yesterday, so I apologize if this is a stupid question. The client requested a JSON / XML type schema for storing the data because they want the flat file to edit / update without having to process requests and they want it to be flexible for future development. I would like the data to be structured, since I will be using it and php to generate html pages, the two parts of the site will use it like they are on the same server.

json file will contain an array of objects, maybe ultimately 50, consisting of 5 or 6 short tags / data combo, and 1-3 tag / data combinations that will be long, a couple of paragraphs of text each.

Details: Server side implementation only, everything will be on the same server. At this time, I will manually create a json file, in the future it can be automatically generated. I prefer json to xml as php is easier to manipulate. I have php 5.2.6 and json 1.2.1.

My questions:

  • Can json be used for data that is textarea sized? Will this cause performance issues when building when I have 30-50 objects in my array and I need to find the right one?

  • Is it appropriate to use json as data store?

  • If so, I am having a hard time finding instructions on the very basics, such as how to access the file. Do I need to use XMLHttpRequest even on the same server? Any informative links to help understand this better would be greatly appreciated.

  • If this is not a good use, any advice on what might be a good choice would be greatly appreciated!

Thank!

+2


source to share


4 answers


JSON sounds like a decent solution to what you are doing given the client's limitation of requiring a flat file. If you are using PHP's built-in jsonencode () and jsondecode () functions, you shouldn't have any problem with the paragraph length data.

You won't have the same query capability as a relational database like MySQL, but if you only need to search and modify in one file at a time, it would be very easy to do in PHP after using jsondecode () and some functions PHP array. Searching across many files at once would be quite difficult, and I would recommend searching a database rather than flat files for something like this.

To open files in PHP, check the file_get_contents () and file_put_contents () functions.



http://us.php.net/manual/en/function.file-get-contents.php

http://us.php.net/manual/en/function.file-put-contents.php

All that said, unless you really need to use a flat file, the other posters are true that the database will be much more versatile. JSON and XML are used much more for transporting data than storing data these days. MySQL has a number of pre-built interfaces (such as PHPMyAdmin) that allow you to search and modify data without using SQL queries.

0


source


  • Probably no.
  • Not. Please use the database, it will save you a lot of headaches in the future.
  • If you must, just use the PHP library to access the json file.
  • Use MySql or equivalent. It looks like you need to generate page data dynamically. This is what MySql was created for (among other things).


+3


source


I'm shocked at reading things like "No modern web application stores data in a flat file."

Did you know that Google and Twitter use flat file systems? Geez ... are growing out of the database era. Unless you're sorting, viewing, and merging thousands of data blocks, mysql doesn't really make sense. Plus, flatfiles tend to be the simplest and most portable (not just for backup reasons).

I would really dive into "reading and writing files". It will also expand your understanding of the basic functionality of php (and your results are likely to be faster).

+1


source


If they really want them flexible, they have to throw their data into the database. This is a much more reliable approach than a flat file. Building a web CRUD (create / update / delete) for the underlying data is a simple pollution.

Answers:

H. If they insist on having a flat version of their data, provide a page on the site that will generate the XML or JSON version of what is in the database. This should make them happy, but save the data in a location that makes sense to use the app.

0


source







All Articles