zoeyfyi / Boop-GTK

Port of @IvanMathy's Boop to GTK, a scriptable scratchpad for developers.
https://boop-gtk.zoey.fyi
MIT License
239 stars 13 forks source link

Support for Jsonc (.json files with comments) #106

Open Eonfge opened 4 years ago

Eonfge commented 4 years ago

Jsonc is a simplified json format which allows comments and unquoted values delimited by whitespace. A jsonc formatted file can be transformed to a json file. Comments will be stripped out and quotes added.

https://komkom.github.io/

Right now, parsing json files with comments, causes it to fail. This is annoying since comments are an all-round good practice and they are often de facto required when working in teams.

zoeyfyi commented 4 years ago

Definitely would be nice to have, I always use JSON parsers that accept comments in my projects.

The scripts are quite easy to generate, for example here is a "format jsonc" script that you can drop into Boop-GTK's scripts folder. This was generated with the following:

const jsonc = require('jsonc-parser');

global.main = function (state) {
   let edits = jsonc.format(state.text, undefined, { tabSize: 4, insertSpaces: true, eol: "\n" });
   state.text = jsonc.applyEdits(state.text, edits);
}

Then following the instructions here.

As far as including it in the default set of scripts, right now all the scripts come from the project this was based of, Boop. I am not sure what the best policy for script requests should be, but perhaps its best to open an issue in the Boop repo, then both projects can benefit.

Eonfge commented 4 years ago

I've reported it upstream. You want to keep this issue open or is this good enough for now?

zoeyfyi commented 4 years ago

May as well keep it open.