 <p>To get rid of line breaks</p> <p>Try:</p> <pre><code>jsonText = jsonText.replaceAll("\n", "\\\\\\\\\\\\\\\\r\\\\\\\\\\\\\\\\n"); // for all occurrence // This will replace \n with \\\\r\\\\n a new line for codemirror </code></pre> <p>or </p> <pre><code>jsonText = jsonText.replace("\n", "\\\\\\\\\\\\\\\\r\\\\\\\\\\\\\\\\n"); </code></pre>