Strip ASCII characters that break JSON parsing

Developer
Size
3,100 Kb
Views
36,432

How do I make an strip ascii characters that break json parsing?

What is a strip ascii characters that break json parsing? How do you make a strip ascii characters that break json parsing? This script and codes were developed by Scott Bram on 11 August 2022, Thursday.

Strip ASCII characters that break JSON parsing Previews

Strip ASCII characters that break JSON parsing - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Strip ASCII characters that break JSON parsing </title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ html { font-family: sans-serif; font-size: 12px;
}
header { margin: 16px 0 8px; padding: 4px 8px; background: gray; color: white; font-weight: bold;
}
input,
textarea { display: block; width: 400px;
}
textArea { height: 150px;
}
#sampleText { width: 400px;
}
#theResult { width: 322px;
}
.forTextInputs { float: left; padding: 5px 4px 0 0;
}
.forTextAreas { display: block; margin: 8px 0 4px;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <header>Sample text with ASCII control character which will break AJAX JSON parsing</header>
<input id="sampleText" type="text" value="He will update us after the meeting." readonly>
<header>Enter some text</header>
<input id="theText" class="getIn" placeholder="(Text input)" type="text"> - or -
<textarea id="theTextArea" class="getIn" placeholder="(Textarea input)"></textarea>
<header>Results</header>
<label for="theResult" class="forTextInputs">Matched with: </label>
<input id="theResult" class="getOut" placeholder="No match" type="text">
<label for="saniText" class="forTextAreas">Sanitized output: </label>
<textarea id="saniText" class="getOut" placeholder="(No fed input to sanitize. Paste here directly to demo behavior in a live field.)"></textarea> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Strip ASCII characters that break JSON parsing - Script Codes CSS Codes

html { font-family: sans-serif; font-size: 12px;
}
header { margin: 16px 0 8px; padding: 4px 8px; background: gray; color: white; font-weight: bold;
}
input,
textarea { display: block; width: 400px;
}
textArea { height: 150px;
}
#sampleText { width: 400px;
}
#theResult { width: 322px;
}
.forTextInputs { float: left; padding: 5px 4px 0 0;
}
.forTextAreas { display: block; margin: 8px 0 4px;
}

Strip ASCII characters that break JSON parsing - Script Codes JS Codes

/** "Input" event requires a modern evergreen browser */
$('#theText, #theTextArea').on('input', function(e) { /** Grab the input string and stuff it in this variable */ var inputText = $(e.target).val(); /** Only act if one of the input fields contains something measurable */ if (inputText.length > 0) {	/** Next 2 conditions will clear the alternate field when something is entered */ if ($(e.target).attr('id') === 'theText') { $('#theTextArea').val(''); } if ($(e.target).attr('id') === 'theTextArea') { $('#theText').val(''); } /** * This will match all ASCII nonprinting/control characters, * except Line Feed and Carriage Return, */ var pattern = /[\x01-\x09\x0B-\x0C\x0E-\x1F]+/gi; /** If the regex pattern is matched... */ if ( pattern.test(inputText) ) {	/** ...get the matched pattern... */ $('#theResult').val( inputText.match(pattern) ); /** ...remove it from the input string and set the result to this variable... */ var saniText = inputText.replace(pattern, ''); /** ...then set that as the field value */ $('#saniText').val(saniText); } else {	/** If the regex pattern is unmatched, reset the results fields */ $('#theResult').val(''); $('#saniText').val(''); } } else {	/** Reset all bound field values if the input fields are empty/emptied */ $('.getIn, .getOut').val(''); }
});
/** See documentation above for details */
$('#saniText').on('input', function(e) { var inputText = $(e.target).val(); if (inputText.length > 0) {	$('.getIn, #theResult').val(''); var pattern = /[\x01-\x09\x0B-\x0C\x0E-\x1F]+/gi; if ( pattern.test(inputText) ) { $(e.target).val(inputText.match(pattern)); var saniText = inputText.replace(pattern, ''); $(e.target).val(saniText); } }
});
Strip ASCII characters that break JSON parsing - Script Codes
Strip ASCII characters that break JSON parsing - Script Codes
Home Page Home
Developer Scott Bram
Username thatbram
Uploaded August 11, 2022
Rating 3
Size 3,100 Kb
Views 36,432
Do you need developer help for Strip ASCII characters that break JSON parsing?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Scott Bram (thatbram) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!