https://github.com/modfin/jct
A lib for toggling json cases.
https://github.com/modfin/jct
Last synced: over 1 year ago
JSON representation
A lib for toggling json cases.
- Host: GitHub
- URL: https://github.com/modfin/jct
- Owner: modfin
- Created: 2019-03-08T17:40:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-20T14:29:27.000Z (over 7 years ago)
- Last Synced: 2025-01-23T09:33:59.989Z (over 1 year ago)
- Language: Go
- Size: 11.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON Case Toggle
A simple tool for toggling different cases in json data.
eg.
```go
j := []byte(`{"ToggleCase": 1}`)
j := jct.Toggle(j, jct.PascalCase(), jct.SnakeCase())
fmt.Println(string(j))
// {"toggle_case": 1}
```
or
```go
j := []byte(`{"some-thing": ["else", {"but-is": "needed"}]}`)
j := jct.Toggle(j, jct.KebabCase(), jct.CamelCase())
fmt.Println(string(j))
// {"someThing": ["else", {"butIs": "needed"}]}
```
## Restrictions
Camel and Pascal case contains more information then delimitede cases such as kebab
or snake case. Camel case contain information about abbreviations which delimitede cases does not.
eg `URLName -> url_name` and the reverse `url_name -> UrlName`
In this sence information is destoyed when converting from Camel or Pascal case to a delimitede case.