Blocks of this format seem to be repeating a lot. It might make sense to write a specialized function or macro for it:

```c
int json_add_field_if_set (yajl_gen g, char const *key, char const *value)
{
  if (strlen (value) == 0) { return 0; }
  /* … */
}
```

Each of these blocks could then be written as a single line:

```c
if (json_add_field_if_set (g, "host", n->host) != 0) { return; }
```