retrieve boolean value?

893 views
Skip to first unread message

Paul Harris

unread,
May 31, 2012, 12:29:12 PM5/31/12
to jansso...@googlegroups.com
Hi all,

The documentation doesn't document the functions json_is_true() and json_is_false()

I had to look in the header file to see that they actually exist.

thanks,
Paul

rogerz

unread,
May 31, 2012, 6:49:17 PM5/31/12
to jansso...@googlegroups.com
On Friday, June 1, 2012, Paul Harris wrote:
Hi all,

The documentation doesn't document the functions json_is_true() and json_is_false()

It is documented under the section "Type". 

The naming of jansson API is very straight forward. If you are using an editor with auto completion, it is quite easy to guess the name of the function. Looking directly in header file or test case is not a bad idea either.


--
 ,---.  Rogerz Zhang
( @ @ ) Human, not octopus
 ).-.(  Chase what you love. Let the rest go.
'/|||\` Code > Github | Note > Tumblr | Random > twitter 微博 | Share > Google+ 
  '|`   AsciiArt < Shimrod(hh)

Paul Harris

unread,
May 31, 2012, 8:09:23 PM5/31/12
to jansso...@googlegroups.com


On Friday, June 1, 2012 6:49:17 AM UTC+8, Rogerz Zhang wrote:
On Friday, June 1, 2012, Paul Harris wrote:
Hi all,

The documentation doesn't document the functions json_is_true() and json_is_false()

It is documented under the section "Type". 

The naming of jansson API is very straight forward. If you are using an editor with auto completion, it is quite easy to guess the name of the function. Looking directly in header file or test case is not a bad idea either.

Ah, sorry, I think it was too late when I wrote that message.
What I was REALLY asking for, was symmetrical API.

* We have json_is_integer() and json_integer_value()
* We have json_is_boolean() so I was expecting to find json_boolean_value() which doesn't exist.

Perhaps something good to add?
and json_boolean() for "creating" a true/false node.

thanks,
Paul

rogerz

unread,
May 31, 2012, 11:28:46 PM5/31/12
to jansso...@googlegroups.com
On Fri, Jun 1, 2012 at 8:09 AM, Paul Harris <harr...@gmail.com> wrote:
On Friday, June 1, 2012 6:49:17 AM UTC+8, Rogerz Zhang wrote:
On Friday, June 1, 2012, Paul Harris wrote:
Hi all,

The documentation doesn't document the functions json_is_true() and json_is_false()

It is documented under the section "Type". 

The naming of jansson API is very straight forward. If you are using an editor with auto completion, it is quite easy to guess the name of the function. Looking directly in header file or test case is not a bad idea either.

Ah, sorry, I think it was too late when I wrote that message.
What I was REALLY asking for, was symmetrical API.

* We have json_is_integer() and json_integer_value()
* We have json_is_boolean() so I was expecting to find json_boolean_value() which doesn't exist.

Actually there's no boolean type in json, (see json.org), only the constant values. So the symmetrical API is json_is_true() and json_is_false()

json_is_boolean() is just a short cut for check if the value is either one.

xgbi

unread,
Jul 24, 2012, 8:05:06 AM7/24/12
to jansso...@googlegroups.com
What's quite disturbing in this, is that to *set* a boolean value, you have to to this:

bool value = true;
json_object_set_new( object, key, value? json_true() : json_false() );

Whereas in every other case, you can use the value in a json_[string|integer|real]() function:

int value = 3;
json_object_set_new( object, key, json_integer(value) );

It is not that trivial to understand; I had to look into the doc to find a trick to set a boolean value in an object.
Maybe there's a better solution?

Is it a major disturbance to have at least a constructor like "json_boolean( bool value )", so that the json_*_set API is consistent?


On Friday, June 1, 2012 5:28:46 AM UTC+2, Rogerz Zhang wrote:

Petri Lehtinen

unread,
Jul 25, 2012, 12:28:06 AM7/25/12
to jansso...@googlegroups.com
xgbi wrote:
> What's quite disturbing in this, is that to *set* a boolean value, you have to
> to this:
>
> bool value = true;
> json_object_set_new( object, key, value? json_true() : json_false() );
>
> Whereas in every other case, you can use the value in a json_[string|integer|
> real]() function:
>
> int value = 3;
> json_object_set_new( object, key, json_integer(value) );
>
> It is not that trivial to understand; I had to look into the doc to find a
> trick to set a boolean value in an object.
> Maybe there's a better solution?
>
> Is it a major disturbance to have at least a constructor like "json_boolean(
> bool value )", so that the json_*_set API is consistent?

Interesting. There have been requests for a better API for boolean
values, but this is the first case that is quite ugly with what we
currently have.

I'll consider adding the following macro to the next major version:

#define json_boolean(value) ((value) ? json_true() : json_false())

In the meantime, you can define it in your own code to make it
simpler.

Petri
Reply all
Reply to author
Forward
0 new messages