Adding some functions to help me simplify JSONL fi...
# cfml-general
m
Adding some functions to help me simplify JSONL files/data, Figured id share what I came up with that has worked thus far and see if anyone has suggestions or UDFs they use to manage JSONL data.
Copy code
function jsonlToArray(jsonl) {
		var result = [];
		var lines = listToArray(jsonl, chr(10));

		for (var line in lines) {
			result.append(deserializeJSON(line));
		}
        
		return result;
	}
    
    function isJSONL(content) {
		
		// Split the file contents by line
		lines = listToArray(content, chr(10));
		
		// Check that each line is a valid JSON string
		for (i = 1; i <= arrayLen(lines); i++) {

			if (!isJSON( lines[i].trim() ) ) {
				return false;
			}
		}
		
		// If we made it this far, it's a valid JSONL file
		return true;
	}
z
a
I've always done this with something like this:
Copy code
array = deserializeJson('[' & fileRead('file.jsonl').replaceAll('[\n\r]+', ',').replaceAll(',$', '') & ']');