translate icon indicating copy to clipboard operation
translate copied to clipboard

WebExtension JSON is not actually JSON

Open nijel opened this issue 7 years ago • 7 comments

The current parser for WebExtension JSON assumes that it js JSON based, however it's not as it expects preparsing to strip comments:

Standards-compliant browsers are expected to ignore "//" comments. Disregarding comments, the manifest.json file format for browser extensions is expected to be fully JSON compliant.

See https://browserext.github.io/browserext/#manifest-json

nijel avatar May 25 '18 06:05 nijel

This is going to be tricky - there doesn't seem to be any Python parser which would allow round trip - all just strip comments and then use standard json library.

nijel avatar May 28 '18 18:05 nijel

Maybe https://pypi.org/project/json_tricks/

nschonni avatar May 28 '18 20:05 nschonni

It doesn't support saving as well:

Since comments aren't stored in the Python representation of the data, loading and then saving a json file will remove the comments (it also likely changes the indentation).

nijel avatar May 28 '18 20:05 nijel

Adapted from https://github.com/WeblateOrg/weblate/issues/2043#issuecomment-393633466:

When importing:

  • Convert comments to some special JSON field so it can be represented in JSON, e.g. "// comment 1 2 3" to "{idSpecialComment_comment_1_2_3}"
  • Exclude them from translations and only use them behind-the-scenes.
  • When exporting (i.e. converting back to JSON) just do the same vice versa.

rugk avatar Jun 21 '18 08:06 rugk

Any news?

rugk avatar Sep 08 '20 12:09 rugk

No news, if there would be any news it would be written here.

nijel avatar Sep 08 '20 12:09 nijel

https://pypi.org/project/jsoncparser/ might be actually a viable solution (at least it claims it supports saving as well)

nijel avatar Mar 24 '22 10:03 nijel