Skip to content

Instantly share code, notes, and snippets.

@funkatron
Created November 4, 2011 14:25
Show Gist options
  • Select an option

  • Save funkatron/1339427 to your computer and use it in GitHub Desktop.

Select an option

Save funkatron/1339427 to your computer and use it in GitHub Desktop.
Encode an arbitrary string as JSON
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Encode string content as JSON</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script>
$(document).ready(function() {
$('#encode').click(function(e){
var input = $('#input').val();
$('#output').val(JSON.stringify(input));
});
});
</script>
<style type="text/css" media="screen">
body {
font-family:Helvetica, Arial, sans-serif;
}
textarea {
width:700px;
height:300px;
}
</style>
</head>
<body>
<h1 id="encode_string_as_json">Encode String as JSON</h1>
<div>
<h2><label for="input">Input</label></h2>
<div><textarea id="input" name="input"></textarea></div>
<div><input type="button" id="encode" name="encode" value="Encode"></div>
</div>
<div>
<h2><label for="output">Output</label><h2>
<div><textarea id="output" name="output"></textarea></div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment