muhammadmuzzammil1998/jsonc

Marshal function

Opened this issue · 7 comments

Please take the next step: Marshal function ...

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

maybe put in tags?

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 😊.

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...."' }

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" 
}
  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.

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.