Jump to content

Topic on Help talk:TemplateData

"Syntax error in JSON" help link does not link to section with help in it

6
Jonesey95 (talkcontribs)

I recently tried to edit Template:Infobox country on en.WP. I made a minor fix to correct a typo, and I received an error message when I attempted to save: "Syntax error in JSON (help)". I subsequently noticed multiple problems:

1. I tried to save again, and the editor let me save the template.

2. I edited the template again to make another small fix, got the same error message, and was unable to save despite four or five attempts. Note that I was NOT trying to modify any JSON, about which I know almost nothing because I have found it to be poorly documented.

3. I clicked on the "help" link, and it took me to a page that did not have a section describing how to respond to this "Syntax error in JSON" message. Please create such a section, knowledgeable people.

4. I was finally able to deduce/guess that the problem was in the template's documentation, not in the template code, even though I was not editing the documentation. I happened upon the link to JSONlint and was able to fix the documentation, which then (apparently) allowed me to save the template.

5. I was able to re-edit the documentation to introduce invalid JSON, with no error message or complaint from MediaWiki: https://en.wikipedia.org/w/index.php?title=Template%3AInfobox_country%2Fdoc&type=revision&diff=914345844&oldid=914345261

Please apply the JSON error-checking code only to the page that contains the JSON formatting information, NOT to the template. At a minimum, please apply the JSON error-checking code to any page containing JSON code so that JSON-deficient/clueless editors such as myself do not get stuck when trying to make valid wikicode edits to template pages. Whoever introduces the invalid JSON code to the documentation should be prevented from saving, not the subsequent template editor.

Rant end. Thanks for reading.

Whatamidoing (WMF) (talkcontribs)
Mvolz (WMF) (talkcontribs)

Not entirely but I can shed some light; this is the result of a combination of several different issues.

One is that the PHP engine we use to validate JSON allows invalid JSON (duplicate keys, trailing commas) which I can't imagine will get fixed anytime soon since we aren't in the business of modifying PHP engines :/ This is the inconsistent behaviour noted in point 5, and was the reason you were able to save invalid JSON: task T128029

There is a task for having JSON in a separate namespace, high priority, that would also help fix this issue of people editing pages with JSON in it but not knowing enough to be able to fix errors in it, task T56140, but it was created in 2013 and no one is working on it as far as I know :/. A band-aid solution is to use transclusion and to have the JSON on a separate page, but this has to be done page by page so it's not a great solution.

As for the help link, I have added a small section about this issue to it here: https://www.mediawiki.org/w/index.php?title=Help%3ATemplateData&type=revision&diff=3408755&oldid=3241880 Although it probably needs some work, and for translate tags to be added, and maybe we should link specifically to that section for that error instead of to the whole help page?

Jonesey95 (talkcontribs)

Item #2 above is the one that really bothered me. I don't know about JSON, I don't really care about JSON, and I wasn't editing a page with any JSON in its code. Nevertheless, I received a JSON error when trying to save code with no JSON in it. That should not happen. Thanks for listening.

Jdforrester (WMF) (talkcontribs)

and I wasn't editing a page with any JSON in its code

But, of course, you were. That's what template transclusion does, unfortunately. It's why it's an anti-pattern. :-(

Mvolz (WMF) (talkcontribs)

Just FYI but we've actually transitioned from HHVM to PHP7 now, which should make at least the problem of people saving invalid JSON because HHVM allowed it a bit better...

Reply to ""Syntax error in JSON" help link does not link to section with help in it"