Putting this here as it is a bit more "exotic", but might still be useful. Just patch this into Hype Data Parser if you need to support JSONL.
https://jsonlines.org/
/**
* Converts a JSONL file to a JavaScript object.
* @param {string} jsonl - The JSONL file.
* @param {object} options - Options for the conversion.
* @param {boolean} options.trim - Trim whitespace
* @param {boolean} options.head - Remove head
* @param {string} options.rSep - Row separator
* @returns {object} - The JavaScript object.
*/
function jsonlToObject(jsonl, options) {
if (typeof(jsonl) !== 'string') return;
if(includesTables(jsonl)) return getTables(jsonl, true);
options = options || {};
options.trim = options.trim || options.trimWhitespace || false;
options.head = options.head || options.removeHead || false;
options.rSep = options.rSep || options.rowSeparator || (getLineBreakChar(jsonl));
jsonl = jsonl.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
var a = {};
var rows = jsonl.split(options.rSep);
if (options.head) {
rows.shift()
}
rows.forEach(function(row, index){
a[index] = JSON.parse(row);
});
return a;
}
Usage:
var jsonl = `{"id":1,"first_name":"John","last_name":"Smith","email":"john.smith@example.com","gender":"Male","ip_address":"1.0.0.0"}
{"id":2,"first_name":"Jane","last_name":"Doe","email":"jane.doe@example.com","gender":"Female","ip_address":"1.0.0.1"}
{"id":3,"first_name":"Bob","last_name":"Smith","email":"bob.smith@example.com","gender":"Male","ip_address":"1.0.0.1"}`;
console.log(jsonlToObject(jsonl));
There is also a version to convert to object key
/**
* Converts a JSONL file to an object with a key
* @param {string} jsonl - JSONL file
* @param {string} key - Key to use as object key
* @param {object} options - Options
* @param {boolean} options.trim - Trim whitespace
* @param {boolean} options.head - Remove head
* @param {string} options.rSep - Row separator
* @returns {object}
*/
function jsonlToObjectByKey(jsonl, key, options) {
if (typeof(jsonl) !== 'string') return;
if (includesTables(jsonl)) return getTables(jsonl, true);
options = options || {};
options.trim = options.trim || options.trimWhitespace || false;
options.head = options.head || options.removeHead || false;
options.rSep = options.rSep || options.rowSeparator || (getLineBreakChar(jsonl));
jsonl = jsonl.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
var a = {};
var rows = jsonl.split(options.rSep);
if (options.head) {
rows.shift()
}
rows.forEach(function(row, index) {
var obj = JSON.parse(row);
a[obj[key]] = obj;
});
return a;
}
Usage:
console.log(jsonlToObjectByKey(jsonl, 'first_name'));