Return empty string "" with JSON Serializer instead of FALSE

Created on 19 November 2021, about 3 years ago
Updated 9 August 2024, 5 months ago

Problem/Motivation

Using JSON Serializer, I'm forced to change some field values to RAW output, in order to display the special characters as they are.

Side effect: When the RAW output is enabled, then the EMPTY string is displayed as

"field_address4": false,

it should be ""

"field_address4": "",

Proposed resolution

I tried with alter the value using hook_views_pre_render()

$field_address4 = !empty($node->get('field_address4')->value) ? $node->get('field_address4')->value : "";

$row->_entity->set('field_address4', $field_address4);
$row->_entity->set('field_address4', (string) $field_address4);

It worked for a while, but the value is again now

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
RESTΒ  β†’

Last updated about 1 month ago

Created by

πŸ‡΅πŸ‡±Poland adpo

Live updates comments and jobs are added and updated live.
  • VDC

    Related to the Views in Drupal Core initiative.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024