JSFiddle - React, Tailwind, and code Playground

by bman654

HTML

Path:
<input id="t" type="text" placeholder="type in a path including backslashes" value="http://somedomain.com/test.jpg?path=\728\1.jpg" />
<br />
<button type="button" id="b">Click</button>
<br />
<div id="result"></div>

CSS

input { width: 400px; }

JavaScript

$(function () {
    $("#b").click(function () {
        var path = $("#t").val();
        var obj = {
            imagePath: path
        };
        try {
            var serialized = JSON.stringify(obj);
            var deserialized = JSON.parse(serialized);
            $("#result").text("serialized='" + serialized + "', deserialized = '" + deserialized.imagePath + "'");
        } catch (e) {
            alert("error serializing: " + e);
        }
    });
});