0

When using JSON:API, the body field of a node (article) is returned like this:

body: {
  format: "basic_html",
  processed: "<p>blah blah blah</p>",
  value: "blah blah blah"
}

However, I just want to return body: "<p>blah blah blah</p>" (the value of processed).

What hook or class method should I use to override this?

1 Answer 1

2

Actually, the JSON:API Extras module includes this feature.

  1. Enable JSON:API Extras resource overrides for Articles at /admin/config/services/jsonapi/resource_types.
  2. On the Article resource override, for the body field, click Advanced, then Single Nested Property, and enter processed as the value.

You can use this technique to drill down into any properties you need, not just the values of text fields.

Warning: Using a Field Enhancer on a field will break POST if you POST to the field alias. Workaround: POST to the actual field name, not the alias.

Many thanks to xaviemirmon in the #decoupled Slack for telling me about this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.