Quotes added to JSON from views_field_view

Created on 18 June 2024, 5 months ago
Updated 24 June 2024, 5 months ago

Problem/Motivation

When adding a JSON view like

  {
    "id": 20,
    "answer": "Multianswer1",
    "followUpQuestions": [
      "752",
      "755"
    ]
  },
  {
    "id": 21,
    "answer": "MultiAnswer2",
    "followUpQuestions": [
      "751"
    ]
  },
  {
    "id": 22,
    "answer": "MultiAnswer3",
    "followUpQuestions": [
      "750"
    ]
  },
  {
    "id": 23,
    "answer": "MultiAnswer4",
    "followUpQuestions": [
      
    ]
  }
]

The view is embedded in quotes in the parent view, so it is now an array, not valid JSON

"answers": "[{\"id\":20,\"answer\":\"Multianswer1\",\"followUpQuestions\":[\"752\",\"755\"]},{\"id\":21,\"answer\":\"MultiAnswer2\",\"followUpQuestions\":[\"751\"]},{\"id\":22,\"answer\":\"MultiAnswer3\",\"followUpQuestions\":[\"750\"]},{\"id\":23,\"answer\":\"MultiAnswer4\",\"followUpQuestions\":[]}]"
 

The issue was also reported in views_field_view and conclusion was that this was not that module's issue https://www.drupal.org/project/views_field_view/issues/2742223

Steps to reproduce

Make a JSON view and embed it in a host view with views_field_view.

Proposed resolution

rest_export_nested should not add quotes to json view it embeds

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇳🇴Norway tnfno

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @tnfno
  • Status changed to Postponed: needs info 5 months ago
  • 🇦🇺Australia imclean Tasmania

    Try this first, from the project page : In your "REST export nested" display, edit your fields settings and select "Raw output" for the JSON field.

    If that doesn't resolve your issue, provide step by step instructions on how to reliably replicate the issue.

  • 🇳🇴Norway tnfno

    I have tried that, both in parent and child.
    If I select RAW in parent view:

    answers": "[{\"id\":3,\"answer\":\"Svar11\",\"followUpQuestions\":[\"744\"]},{\"id\":2,\"answer\":\"svar3\",\"followUpQuestions\":[\"744\"]},{\"id\":1,\"answer\":\"Ansver34\",\"followUpQuestions\":[\"745\",\"744\"]}]"

    changes to

    answers": null

    If I change it in for fields in child view it is unchanged.

    So everything works, except the JSON from the child view gets embedded in quotes.

    I have attached two screenshots of the parent and child view page.

    Since the output of the child view looks OK, I believe the quotes are added by the parent view.

    Will make stripped down example with instructions to reproduce.

  • 🇦🇺Australia imclean Tasmania

    Create the simplest views possible to replicate the problem, export their config, and upload it here so we can test using exactly the same configuration.

  • Status changed to Closed: works as designed 5 months ago
Production build 0.71.5 2024