jsonc icon indicating copy to clipboard operation
jsonc copied to clipboard

Marshal function

Open Caledfwlch1 opened this issue 4 years ago • 7 comments

Please take the next step: Marshal function ...

Caledfwlch1 avatar Jul 09 '20 14:07 Caledfwlch1

Yeah... You know what? I'll look into it. Thanks! Any suggestions for how the comments should be structured?

muhammadmuzzammil1998 avatar Jul 09 '20 20:07 muhammadmuzzammil1998

maybe put in tags?

Caledfwlch1 avatar Jul 10 '20 17:07 Caledfwlch1

Yes it has to be done with tags but how would the syntax be? Just like jsonc:"key" anything here will be considered a comment or have a specific syntax?

PS: I haven't worked with tags yet. Will have to take a look on how they work to finalize a syntax. Thanks for your interest 😊.

muhammadmuzzammil1998 avatar Jul 10 '20 17:07 muhammadmuzzammil1998

Please look at that tag. This is not difficult. :) This will reduce a speed, but comments are usually needed in the configuration file, in which case this is not critical. I liked your idea! structure{ Field string 'json:"field" comment:"this field...."' }

Caledfwlch1 avatar Jul 11 '20 07:07 Caledfwlch1

Thanks! But could you please tell:

  1. Should this support only jsonc tag or both jsonc and json tag? I don't see why it shouldn't. What do you think?

  2. Where do you think the comments should be placed?

{
  "key": "value" // comment here (my preference)
}

OR

{
  // comment here
  "key": "value" 
}

muhammadmuzzammil1998 avatar Jul 12 '20 13:07 muhammadmuzzammil1998

  1. I think you should not overload the JSON tag. If you are not using the JSONC tag now, then it's time. :)
  2. I also like the first example.

Caledfwlch1 avatar Jul 14 '20 14:07 Caledfwlch1

I know I'm late, but just around this time I wrote a go module that does exactly what you need and its MIT licensed.

It is not based on tags, but on parsing the abstract syntax tree of the go source.

Distinguishes both documentation blocks and inline comments, and reads any default values specified in a method with a specific signature (see the readme).

If you think it could be useful, use it freely and let me know what you think: https://github.com/marco-sacchi/go2jsonc

Note that go2jsonc is a static analysis / generator tool and its not reflection based, so you need to specify the package path and type name, not the package import string.

marco-sacchi avatar Jun 08 '22 10:06 marco-sacchi