-
Notifications
You must be signed in to change notification settings - Fork 498
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
API changes proposal #37
base: master
Are you sure you want to change the base?
Conversation
// using GetIndex(). | ||
// | ||
// js.GetPathAny("top_level", "entries", 3, "dict") | ||
func (j *Json) GetPathAny(branch ...interface{}) *Json { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just update GetPath
to behave like this, it won't be backwards incompatible...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I tried that at first, but one of the tests gave an error about converting []string to []interface{}, so it's not fully compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, when passing v...
as the argument where v
is []string
, hmmmm
looks fine otherwise, API bloat aside. We really need to think about |
I'm currently using this extensively in a project, and feel the need for a few changes. |
How about writing up an issue with your proposed changes/API here on this repo so we can plan the next version? |
I don't have anything clear just yet, but I'll see what I can do. |
- Get() now works like the old GetPathAny() - Reworked CheckGet() to also take a path - Removed GetIndex(), GetPath() and GetPathAny() because the new Get() supersedes them.
Too specific, should use Array() or JsonArray() instead, and then cast the individual values as the type that you need.
- Added "Check" prefix to the ones that also return an error. - Removed the "Must" prefix from those that always return a valid value. fixes issue bitly#15
Alright, Updated the first comment with more changes. |
nice work @AzuraMeta another naming suggestion. I think |
Done :) |
also, since we only really ever generate our own errors, it's possible that the |
It's not a cast, but a straight-up conversion, with limited uses. Also, fixed JSON*() descriptions.
I also thought of that, but CheckUint64() uses strconv.ParseUint() which can return a more complex error. Maybe we should change that instead, using string for a number conversion is weird in the first place... |
It needs to use that for big numbers, I think. |
Alright did it anyway, I simply ignored the error details in those specific cases. PS: When we're all done with the changes, I'm gonna re-organize the code a bit, but until then I don't wanna mess-up the diff too much. |
this is looking great! FWIW I meant all instances of This would give people the opportunity to transition seemlessly for eventual deprecation of the old API. Thoughts @jehiah |
If you're suggesting to bundle both versions in the same package, I disagree. Instead of one bloated api you'd get a huge api with 2 sub-apis, and new people would be confused as to which they should use. I think the best course would be to have the new api in a different repo, with a link at top of this one's readme. That way existing users could safely update, while new ones will see the new version right away. Also, I'm not sure how to handle the remaining issues:
fmt.Println(js.Get("a_list").Array()) //let's say it would print 2 elements
lsj := js.Get("a_list").JsonArray()
lsj = append(lsj, simplejson.New())
js.Set("a_list", lsj)
fmt.Println(js.Get("a_list").Array()) //this will print empty The cause for this is that Array() doesn't recognize []_Json as a valid array. And it's not just Array() and Map(). |
|
|
Hey I was wondering, should the Int(), Float64() etc..., convert from strings? jsStr := `{"test":"24"}`
js, _ := simplejson.NewJSON([]byte(jsStr))
fmt.Println(js.Get("test").Int()) //this would currently print 0 |
I don't think so, but I'm open to other opinions |
Forked go-simplejson, incorporated most of the changes from this pull request and added a few extra functions for manipulating JSON files. If it's of any interest, the resulting repository is here. |
Edit: No point in closing and re-opening the pull request, I'll just generalize this one.
So, I have a few suggestions for the next version of the API:
API bloat reduction:
Navigation improvement:
Naming conventions:
For reference, doc link for the modified API: http://godoc.org/github.com/AzuraMeta/go-simplejson