3

A. I store tags in a database which are user input.

B. For views, a group of these tags are then fetched with a query and concatenated.

C. I iterated this format and print each tag in the view.

For part B I create a JSON array with the concatenation in the query. But now I'm thinking it might be worthwhile to pick an even more lightweight format than JSON. My reasoning is it would make it simpler to validate the user tags coming into the database.

If I were to choose one delimiter, say , to identify tokens would the only validation needed be disallowing this character for tags?

1
  • I am thinking of making sandwhiches. Is the only thing not considered a topping bread? I think we need to see a lot more of your proposed implementation. JSON is super lightweight, when done correctly, so you're trading more processing time and logic for saving about six characters. Commented May 7, 2012 at 16:31

1 Answer 1

2

But now I'm thinking it might be worthwhile to pick an even more lightweight format than JSON.

Why do you think so? More often than not, using JSON simplifies things a lot both on the frontend and the backend because you can do a json_decode in PHP and just an eval JSON.parse in Javascript and then your JSON data will be translated to native objects in the respective language which you can then manipulate easily. So I would recommend you stick to JSON.

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

3 Comments

errr, don't use eval in javascript. use a native or json.org json parser, don't use eval in javascript.
@jcolebrand Thanks for that! I usually rely on jQuery to do the translation. Read up just now on why eval is a bad idea.
If you want some detailed examples of why eval is bad, check here on Stack Overflow, there's even some dedicated questions to that ;-)

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.