EscapeForJSON Plugin for Movable Type

Download

EscapeForJSON v1.0 (1 KB) — 17 May 2017

About

JSON string encoder for Movable Type.

Usage in Movable Type templates (particularly useful for JSON feeds):

<MTEntries lastn="5">
"content_html" : "<MTEntryBody escape_for_json='1'>"
</MTEntries>

Basic JSON string escaping: \, ", whitespace and control characters.

I wrote this because MT’s built-in escape="js" and encode_js="1" tag filters are overzealous in what they escape (for example, backslash-escaping every < and >), which makes the output ugly, and a big part of JSON Feed’s appeal is that feeds look good to the human eye.

Also included: an example JSON Feed index template for Movable Type.

Installation

Unzip, and copy the “EscapeJSON.pl” file to the plugins directory of your Movable Type installation, e.g.:

(MT home)/plugins/EscapeJSON.pl