0

I have a rest export view and this is my output:

{
  title: "about",
  view: "[{"id":7,"field_history_json":7,"field_history_text":"sdfsfsdffd","field_history_year":3244}]"
}

My field "view" is a string and I need this to be an object/array, like this.

{
  title: "about testes",
  view: [
    {
      id: 1,
      field_history_json: 1,
      field_history_text: "sdsdfsfsfd",
      field_history_year: 234
    }
  ]
}

Like I said I have a rest export view of "About" content type. "About" content type has a paragraph field. Paragraph field has 3 fields (text, year and file).

I also have a rest export nested view, this view has paragrpah fields that I want to display.

I import paragraph view (rest export nested view) to my first view ("About") and display it with "Views field view" module.

That's how I am getting output as string.

Is there a way to convert string to JSON object in Drupal 8?

  • 2
    Look into creating your own Normalizer class. It will allow you to create the response shape you want. – Kevin Aug 2 at 18:05
  • Thanks for the reply @Kevin I will search more about that. If you know any good tutorial/explain how to do it step by step let me know please. I'm new at JSON and Normalizer class. – Pedro Aug 7 at 9:48
  • Serialization API doc page: drupal.org/docs/8/api/serialization-api/… Blog post on using normalizers to alter data: mediacurrent.com/blog/… – Steven Aug 7 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.