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

Change representation of JSON null to symbol null #31

Closed
johnwcowan opened this issue Jan 2, 2019 · 4 comments · Fixed by #57
Closed

Change representation of JSON null to symbol null #31

johnwcowan opened this issue Jan 2, 2019 · 4 comments · Fixed by #57

Comments

@johnwcowan
Copy link

In the current version of guile-json, JSON null is represented internally as #nil. Because of the magic behavior of #nil, this causes certain problems when trying to discriminate between various internal JSON representations. For example, the programmer will expect (list? j) to detect a JSON object and (null? j) to detect an empty JSON object. But these type discriminators are not correct, because they will also return #t on #nil. So one must write unidiomatic things like (or (pair? j) ((eq? j '())) instead of (list? j).

I suggest (even though it is yet another breaking change) switching to the Scheme symbol null. This is portable, printable and rereadable, and not subject to the above problems. It is also what Racket and the Chicken medea egg (not the json egg) use.

@johnwcowan johnwcowan reopened this Jan 2, 2019
@johnwcowan
Copy link
Author

oops

@bjoli
Copy link

bjoli commented Apr 28, 2020

The racket json library uses a (json-null) parameter for the null value and an optional argument for most procedures that default to (json-null). That seems like a flexible enough way to do it.

@johnwcowan
Copy link
Author

johnwcowan commented Apr 28, 2020 via email

aconchillo added a commit that referenced this issue May 10, 2020
This patch introduces a breaking change since JSON null is now mapped to the
symbol 'null (see #31).

However, this default value can be modified in all public function by
providing the #:null key argument.

Fixes #31
aconchillo added a commit that referenced this issue May 10, 2020
This patch introduces a breaking change since JSON null is now mapped to the
symbol 'null (see #31).

However, this default value can be modified in all public function by
providing the #:null keyword argument.

Fixes #31
@aconchillo
Copy link
Owner

aconchillo commented May 10, 2020

There's a bunch of people using guile-json and making this and #33 would be too much of a breaking change, plus I like supporting symbols when building alists for example.

So, with this in mind, I went for the flexible solution suggested by @bjoli in #57. I'd love if you could take a look.

aconchillo added a commit that referenced this issue May 10, 2020
This patch introduces a breaking change since JSON null is now mapped to the
symbol 'null (see #31).

However, this default value can be modified in all public function by
providing the #:null keyword argument.

Fixes #31
aconchillo added a commit that referenced this issue May 10, 2020
This patch introduces a breaking change since JSON null is now mapped to the
symbol 'null (see #31).

However, this default value can be modified in all public function by
providing the #:null keyword argument.

Fixes #31
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

Successfully merging a pull request may close this issue.

3 participants