Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word convention for JSON #47

Open
cv21 opened this issue Mar 12, 2020 · 5 comments
Open

Word convention for JSON #47

cv21 opened this issue Mar 12, 2020 · 5 comments

Comments

@cv21
Copy link

cv21 commented Mar 12, 2020

Sometimes it matters which word convention do you use.

For example, in some projects it is a rule to use only snake_case in json properties.

Now we do not have any options for the problem. I suggest to add some flag for word convention.

@smyrman
Copy link

smyrman commented Mar 12, 2020

What are you planning on controlling with such a flag? You can already control which fields to use by using struct tags or naming your input variables to service functions.

As for the fields in the JSON RPC response itself, the names has to follow the JSON RPC spec.

@cv21
Copy link
Author

cv21 commented Mar 13, 2020

@smyrman , the JSONRPC spec does not specify json word convention.

lowerCamelCase variant:

--> {"jsonrpc": "2.0", "method": "someMethod", "params": {"someParam": 23, "someOtherParam": 42}, "id": 3}
<-- {"jsonrpc": "2.0", "result": 19, "id": 3}

snake_case variant:

--> {"jsonrpc": "2.0", "method": "some_method", "params": {"some_param": 23, "some_other_param": 42}, "id": 3}
<-- {"jsonrpc": "2.0", "result": 19, "id": 3}

The both are possible by the spec. The both are usable. But only one works now.

@smyrman
Copy link

smyrman commented Mar 16, 2020

Sorry for being unclear, I was referring to the reserved words (jsonrpc, method, params, result, error). But I guess all of these (except jsonrpc) are single words.

But to achive what you want, you should be able to do the following?

func (srv *Service) Some_method(some_param, some_other_param int) (*int, *zenrpc.Error) {
}

Not saying this is nice in Go, but you could solve that by letting the service method become a thin wrapper for your actual (private) method with propper naming.

And for nested data-structures, rely on json-tags.

@cv21
Copy link
Author

cv21 commented Mar 17, 2020

Thank you so much for such tricks, @smyrman.

As you mention, it is technically possible to solve the problem using current state of zenrpc, but I believe we can improve zenrpc and make it more convenient and less tricky.

@vetcher
Copy link
Contributor

vetcher commented Dec 3, 2020

This feature is available in my old pr and can be easily copied to some fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants