Usage

This page show how to setup JSED for your own project. It is assumed that the JSED library files are contained within the directory lib/jsed/dist/. You should replace this path with the path in which the files are actually stored. For an example, you could also clone this GitHub repository and open index.html in your own browser, because the table found on the Why page is generated from a JSED file (file path: demo/why.jsed). This would not be possible with, for example, a plain JSON file.

Required Initialization

These script elements should be executed before JSED can be used.

<script src="lib/jsed/dist/jsed.min.js"></script> <script src="lib/jsed/dist/lib/current-executing-script/current-executing-script.min.js"></script>

Optional Initialization

These script elements should be executed before JSED can properly be used for zip and csv files.

<script src="lib/jsed/dist/lib/zip/zip.js"></script> <script src="lib/jsed/dist/lib/zip/inflate.js"></script> <script src="lib/jsed/dist/lib/zip/deflate.js"></script> <script> zip.useWebWorkers = false; </script> <script src="lib/jsed/dist/lib/papaparse/papaparse.min.js"></script>

JSED File Syntax Each JSED file should only contain a call to this function with the specified parameters:

JSED.execute(fileFormat, encodingsString, encodedData);

fileFormat: String representing the file format of the encoded data. encodingsString: String that contains different encoding methods separated by commas. The order of the encodings is such that the first method is the outermost encoding method with which encodedData has been processed. For example, if encodingsString = "base64, base32", then encodedData has first been encoded with the base32 algorithm and then with the base64 algorithm. This means that for correct decoding encodedData should first be decoded with base64 and then with base32. encodedData: String that contains the encoded data. JSED Usage Syntax To parse a JSED file, call this function

JSED.parse(src, onCompleteCallback, async = true, reload = false);

src: String representing the URL to the JSED file. onCompleteCallback: A function that takes an object as an argument. The object represents the result of the parsing process. The function is called when the parsing process has been completed. async: Boolean stating whether the script element is loaded asynchronous or not. The parsing process is always asynchronous. Defaults to true. reload: Boolean stating whether the entire parsing processed should be recompleted. If the value is true and src has already been parsed and is still stored in memory, then onCompleteCallback will be immediately called with the stored value. This saves computation time on subsequent calls. Defaults to false.

To clear the results stored in memory, use:

JSED.clearState(src);

src: String representing the URL to the JSED file of which the in memory data should be cleared.

Examples

Here are some examples of what the contents of JSED files may look like. Additionally, the files can be parsed, after which the result is displayed as a string in the output box. The result is also logged in to the console, which allows for more indepth inspection.

CSV Example File content:

JSED.execute("csv", "base64", "aWQseCx5LHoNCjEsMiwzLDQNCjIsMywyLDENCjMsMiwyLDINCjQsMSwxLDENCjUsOCw5LDg=");

JavaScript:

JSED.parse('demo/data/jsed/example-csv.jsed', function (parsedData) { // Assume that getOutputElement() is a function that // returns the correct output textarea. The value // of the output textarea is set to the JSON serialization // of parsedData, just so that it can be displayed. var outputElement = getOutputElement(); outputElement.value = JSON.stringify(parsedData); console.log(parsedData); };

Execute JavaScript Open Origin File Result (view details in the JavaScript console):



HTML Example File content:

JSED.execute("html", "rot13, base64", "CTEcqw4APtx8pQ4APtxWFTIfoT8tCUAjLJ4tp3E5oTH9VzAioT9lBvOlMJDvCaqipzkxVGjip3Ouow4APtx8Y3N+QDb8Y2Ecqw4=");

JavaScript:

JSED.parse('demo/data/jsed/example-html.jsed', function (parsedData) { // Assume that getOutputElement() is a function that // returns the correct output textarea. The value // of the output textarea is set to the JSON serialization // of parsedData, just so that it can be displayed. var outputElement = getOutputElement(); outputElement.value = parsedData.innerHTML; console.log(parsedData); };

Execute JavaScript Open Origin File Result (view details in the JavaScript console):



JSON Example File content:

JSED.execute("json", "text", '{ "name": "hello", "content": "world" }');

JavaScript:

JSED.parse('demo/data/jsed/example-json.jsed', function (parsedData) { // Assume that getOutputElement() is a function that // returns the correct output textarea. The value // of the output textarea is set to the JSON serialization // of parsedData, just so that it can be displayed. var outputElement = getOutputElement(); outputElement.value = JSON.stringify(parsedData); console.log(parsedData); };

Execute JavaScript Open Origin File Result (view details in the JavaScript console):



TXT Example File content:

JSED.execute("txt", "", "Hello World!");

JavaScript:

JSED.parse('demo/data/jsed/example-txt.jsed', function (parsedData) { // Assume that getOutputElement() is a function that // returns the correct output textarea. The value // of the output textarea is set to the JSON serialization // of parsedData, just so that it can be displayed. var outputElement = getOutputElement(); outputElement.value = JSON.stringify(parsedData); console.log(parsedData); };

Execute JavaScript Open Origin File Result (view details in the JavaScript console):



ZIP Example File content:

JSED.execute("zip", "base64", "UEsDBBQAAAAIAMVA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{ // Assume that getOutputElement() is a function that // returns the correct output textarea. The value // of the output textarea is set to the JSON serialization // of parsedData, just so that it can be displayed. var outputElement = getOutputElement(); outputElement.value = JSON.stringify(parsedData); console.log(parsedData); };

Execute JavaScript Open Origin File Result (view details in the JavaScript console):





JSED Limitations

Currently this library does not support writing and converting plain data to the JSED format. Vanilla JavaScript executed from a browser does not even have any file write permissions, except that of downloading a file to a location specified by a user. However, this is usually only a minor inconviniece since often developers have access to a backend language with full permissions. The following code creates the file "example.jsed" in PHP, where the created file contains the base64 encoded data of a zip file. The code is relatively easy to understand and replicate in other languages, even if you have no experience with PHP.