Return empty string "" with JSON Serializer instead of FALSE

Created on 19 November 2021, over 2 years ago
Updated 30 January 2023, over 1 year 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

9.5

Component
RESTΒ  β†’

Last updated 7 days 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

Comments & Activities

Not all content is available!

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

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.69.0 2024