camelCase json for Golang struct tags
Hi! How to convert SomeValue `json:"some_value"` auto completion to SomeValue `json:"someValue"?
I have the same question with the thread above. However upon following the instructions, I still get the snakeCase() result .
I'm using Goland 2019.2.2. Can someone confirm whether this is a bug?
Please sign in to leave a comment.
It works fine for me in 2019.2.3. Please ensure that you configure the template variable as on picture below.
Hello, I have done that, and now is not auto-completing anymore, even if I revert to `snake case` it still does not autocomplete.
Could you please help me?
There's a button on the right which is called Restore deleted defaults. Does it help if you apply it to json?
No, still the same
Ok, I have manage to fix it with camelCase, thanks
Hi, I have Goland 2021.1.1 and the only place I could find this setting is in Go Struct Tags / json. However, modifying it using "Edit Variables" does not seem to be working and I continue to get snakecase instead of camelcase when auto completing for json tags.
Could you pl. confirm instructions for obtaining json struct tags in camelcase format for Goland 2021.1.1? Thanks.
Hey, it's much easier in 2021.1. You can convert existing tags by hitting Alt+Enter on them. After that, GoLand will automatically infer style from existing tags. Here you can find more details https://www.jetbrains.com/go/whatsnew/#working-with-json
Cool, I like the new feature and it would be so much more powerful if we can configure the default formatting behavior. I am still wondering if there is a way I can change the default behavior from snake-case to camel-case? I used to be able to do that in previous versions, so it is much easier to simply do back-tick+json+tab and have these struct tags autocomplete with desired format configured in settings. Updating the format in Live Template / Go Struct Tags / json panel does not seem to be working for me and the option to configure the same in Live Template / Go / json panel seems to have been removed in 2021.1.
Hi Saurabh Deoras, the new templates inside backticks always produce struct tags with snake_case and there is no way to configure it yet.
You can create your own template under Preferences / Settings | Editor | Live Templates | Go Struct Tags with the following parameters:
After that, you can invoke json abbreviation without backticks. Please see the example below.
I've filled out a new ticket, please see GO-11005. Autodetection can help your write the correct struct tag once, then GoLand inserts new fields with your camelCase/snake_case/etc preferences instead of configuring the default behavior for each struct tag.
I hope it helps.
Hi Daniil, thanks so much, that worked!
This appears to be a regression from how struct tags previously worked. It used to be possible to apply additional tags that conformed to the live templates defined in Preferences / Settings | Editor | Live Templates | Go Struct Tags.
Previously when I needed to add additional tags I could type the tag name and hit tab to apply. Now custom tags defined in the Live Template settings are no longer picked up and are unusable. If I attempt to use the custom tag first and then type "json" it applies the snake case form of the field name.
Is there any way to achieve what I'm describing above?
Hello @...,
You can still use custom tags in the structs. We have several usability problems, and it may look a bit difficult to use, please see GO-11442 & GO-11465. I see that you voted for GO-11005 as well.
There is one hint that allows you to use json custom tag with camelCase.
Thanks for the explanation Daniil. This is exactly the workaround I needed for the workflow I have. I've voted for the other 2 issues that you've linked. Appreciate your help!
For anyone still encountering this, on the latest version, it seems that it's possible to make the autocomplete pop up by exiting the initial window that appears when writing the tag name, and then writing the tag name that you want to autocomplete.
I'm not sure why this behavior is like that, but I'm guessing the initial autocomplete takes its data from somewhere else, and doesn't take Live Templates into consideration.
It's working like this for me on IDEA 2021.2.2, not sure about Goland.