JSON field formatter

Categories

Component ID

2260965

Component name

JSON field formatter

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

917

Component created

Component changed

Component body

Formats a text field as encoded JSON. This can be useful in combination with Views Datasource.

Currently it supports:
- text
- text_long
- text_with_summary

What is does:
It formats your field as encoded JSON.

How it works:
It passes the raw value of a field (say a body field with a lot of html markup) through the function "drupal_json_encode".

When to use:
If you want to escape your html fields for using in Views Datasource / Views JSON. That module doesn't handle 'raw' formats very well.

Original HTML

<h2>Header2</h2>
<p>Paragraph with&nbsp;<a href="http://drupal.org">link to drupal.org</a>.</p>
<h3>Header3</h3>
<p>Another paragraph.</p>
<ul>
  <li>list item a</li>
  <li>list item b</li>
</ul>

Encoded JSON (via drupal_json_encode)

"\u003Ch2\u003EHeader2\u003C\/h2\u003E\r\n\r\n\u003Cp\u003EParagraph with\u0026nbsp;\u003Ca href=\u0022http:\/\/drupal.org\u0022\u003Elink to drupal.org\u003C\/a\u003E.\u003C\/p\u003E\r\n\r\n\u003Ch3\u003EHeader3\u003C\/h3\u003E\r\n\r\n\u003Cp\u003EAnother paragraph.\u003C\/p\u003E\r\n\r\n\u003Cul\u003E\r\n\t\u003Cli\u003Elist item a\u003C\/li\u003E\r\n\t\u003Cli\u003Elist item b\u003C\/li\u003E\r\n\u003C\/ul\u003E\r\n"