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

toArray() method implementation #42

Open
beeyev opened this issue Mar 4, 2023 · 2 comments
Open

toArray() method implementation #42

beeyev opened this issue Mar 4, 2023 · 2 comments
Assignees
Labels

Comments

@beeyev
Copy link

beeyev commented Mar 4, 2023

Firstly, thanks for the great package, I really like using it.

One question, is it possible for you to implement toArray() to get an array representation of the json ?

@localheinz localheinz self-assigned this Mar 13, 2023
@localheinz
Copy link
Member

@beeyev

Thank for opening an issue!

I am not sure whether adding this method would make sense, since a JSON string could be decoded to

  • an array
  • an object
  • a string
  • a number (an int or a float)
  • a bool
  • a null

If I wanted to do it consistently, I would have to

  • add all of these methods
  • in each of these methods, throw an exception if the JSON string does not decode to the corresponding type

What do you think?

@beeyev
Copy link
Author

beeyev commented Mar 13, 2023

From my perspective these three are enough: array, object, string.

in each of these methods, throw an exception if the JSON string does not decode to the corresponding type

I would propose to change the default behavior, and throw an exception if source JSON is invalid when Json object is constructed. By doing this, we make sure that Json object always contains correct JSON data inside.

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

No branches or pull requests

2 participants