Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing comments from JSON files #7

Merged
2 commits merged into from
Dec 17, 2010
Merged

Removing comments from JSON files #7

2 commits merged into from
Dec 17, 2010

Conversation

jasonlong
Copy link

Hi Anthony,

I'm in the process of rebuilding my site and I'm making use of Stacey's JSON support. I noticed that my AJAX calls were failing because MooTools was saying that the returned JSON was invalid. I ran the output through a couple of online validators and sure enough, it was invalid with the footer comment. I did a little more research and found that there is apparently no comment delimiter to the JSON spec.

I posted a comment on the Get Satisfaction forum the other day:
http://getsatisfaction.com/stacey/topics/json_files_outputted_by_stacey_cant_be_parsed_with_jquery

... but I figured it made more sense to offer a fix for the issue. This commit includes the following:

In cache.inc.php:

  • A $filetype class variable which uses your regex, but now wrapped in a set_filetype() function.
  • An array for filetypes that should not get comments. Right now this is just json, but if more come up in the future, they can just be added here.
  • A new array for defining start/end comment tags. It's now a little easier to see what's going on and it'll be easier to add new ones in the future.

I also created a json example template, so the example site now outputs a JSON object with the projects when you hit /json. The only minor snag I hit there was that when I output the array of images, I only want to put a comma after the entry when we're not on the last image (which I can do with the array of projects, using @is_last), but I didn't see a variable that can check that.

Anyhow, take a look over my changes and let me know what you think. I can be reached at jason@blackantmedia.com.

Thanks!

Jason

@kolber
Copy link
Owner

kolber commented Dec 17, 2010

Beautiful work. Changes are merged into master.

@alibosworth
Copy link
Contributor

@blackant I seem to have run into an issue where generated JSON files are never retrieved from the cache, did you not run into this? I've posted an issue here if you have any thoughts: #37

@alibosworth
Copy link
Contributor

@blackant, if you are curious I solved this issue here: #38

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants