[ANN] Reader to remove comments from JSON

375 views
Skip to first unread message

Giulio Iotti

unread,
Nov 17, 2015, 6:30:43 AM11/17/15
to golang-nuts
With this I am trying to win the "Most Useless Go Package 2015"--before it is even invented.

I made a super-simple Reader that removes those #-to-end-of-the-line comments as it reads a JSON-ish file (quotes and escapes are taken into account.)

Of course no formal parsing, but works generally. Most importantly, with this I can write comments in those (...ehm... awful) JSON config files we sometimes create.

Feel free to copy-paste if you find useful.


-- 
Giulio Iotti

Klaus Post

unread,
Nov 17, 2015, 6:46:17 AM11/17/15
to golang-nuts
On Tuesday, 17 November 2015 12:30:43 UTC+1, Giulio Iotti wrote:
With this I am trying to win the "Most Useless Go Package 2015"--before it is even invented.

I am not sure you are making the world a better place with this package. You should probably have a disclaimer "If you intend to use this package you are probably doing something wrong" ;)

Sorry for teasing you, you probably have a good use case for it, I just couldn't resist :)


/Klaus

Giulio Iotti

unread,
Nov 17, 2015, 6:53:13 AM11/17/15
to golang-nuts
On Tuesday, November 17, 2015 at 12:46:17 PM UTC+1, Klaus Post wrote:
I am not sure you are making the world a better place with this package. You should probably have a disclaimer "If you intend to use this package you are probably doing something wrong" ;)

True, will do.

But I have lost my battle against JSON configuration files a while ago ;)

-- 
Giulio Iotti 

HaWe

unread,
Nov 17, 2015, 8:53:22 AM11/17/15
to golang-nuts
Sorry to say this, but ... it looks useful to me. Thanks for sharing.
(Use case: generate code with text/template and data from JSON file.)

Tim Hawkins

unread,
Nov 17, 2015, 10:17:08 AM11/17/15
to HaWe, golang-nuts

Perhaps we should push for the official adoption of jsonnet as a standard config format.

https://google.github.io/jsonnet/doc/


On Tue, Nov 17, 2015, 22:53 HaWe <hwhe...@bitloeffel.de> wrote:
Sorry to say this, but ... it looks useful to me. Thanks for sharing.
(Use case: generate code with text/template and data from JSON file.)

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Hawkins

unread,
Nov 17, 2015, 10:17:39 AM11/17/15
to HaWe, golang-nuts

roger peppe

unread,
Nov 17, 2015, 12:08:12 PM11/17/15
to Tim Hawkins, HaWe, golang-nuts
On 17 November 2015 at 15:16, Tim Hawkins <tim.th...@gmail.com> wrote:
> Perhaps we should push for the official adoption of jsonnet as a standard
> config format.
>
> https://google.github.io/jsonnet/doc/

Interesting, but I'm not keen. One of the key properties of JSON is
the ability to read, process and write with no data loss. That's going
to be really hard with something like jsonnet.

I'd like to see something directly one-to-one
with JSON but syntactically more friendly. I made
rjson (github.com/rogpeppe/rjson) with this kind of
aim, but it would be nice to have better sugar for
multi-line strings.

Marten Luter

unread,
Nov 17, 2015, 1:43:18 PM11/17/15
to golang-nuts
It's very usefull . Comments is a must in alot of config files. Even not comments itseld but it always happened that you should switchoff something and I always need to write such kind of preprocessor.
Reply all
Reply to author
Forward
0 new messages