I have a view that is outputing a single integer field for each row using JSON. If a field has the value 0 it is not being displayed. I think the problem is here on line 158 of views_json.module:

158     if (empty($field->options['exclude']) && ($field_output != "") && !empty($field_output)) {
159       $object = new stdClass();

If $field_output = 0 then !empty($field_output) will return FALSE and the field will not be rendered.

Comments

kle’s picture

Status: Active » Needs review
StatusFileSize
new1.21 KB

Thank you - I was searching this lines...

Here is a Patch which respects the 'empty'-behaviour in a better way:
1. it's hidden only if it is empty AND "Hide if empty" is TRUE
2. if it is displayed but is empty AND a "No results text" is given -> this text is used.

Maybe not perfect but better than before.
Nice work anymore - greetings from Cologne.

rooby’s picture

Thanks for the patch.

It didn't apply for me for some reason but here is a re-roll with a couple of minor changes.
There were a couple of whitespace and comment changes and where it occurs I replaced:

<?php
(($field_output == "") || empty($field_output))
?>

with:

<?php
empty($field_output)
?>

Because empty() also covers "".

alexander allen’s picture

Assigned: alexander allen » Unassigned

Great job. I also had the same issue. I tested all the use cases mentioned in comment #1 and the solution works as expected. The re-rolled patch didn't apply cleanly for me, I think the patch needs to be created relative to the project itself and not a particular file.

Committed into 7.x-1.x.

alexander allen’s picture

Assigned: Unassigned » alexander allen
Status: Needs review » Fixed
alexander allen’s picture

Status: Fixed » Closed (fixed)
alexander allen’s picture

Status: Closed (fixed) » Fixed

I'm sorry, the correct status is fixed.

Assigned: Unassigned » alexander allen
Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

muhleder’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Closed (fixed) » Reviewed & tested by the community

This also applies to the 6.x branch. The same patch works.

yannickoo’s picture

Status: Reviewed & tested by the community » Fixed

Fixed with 3fc7248.

yannickoo’s picture

Assigned: alexander allen » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.