using only fix arrangements:
if the text variable has that txt you can do this:
var arreglo = texto.split(/\r?\n/).map(function(linea){
return linea.split(' ');
};
var arregloJson = JSON.stringify(arreglo);
That way arrangement is equal to:
[[0, 69, 164], [0, 71, 117], etc... ]
and arrayJson is equal to string JSONeado :
"[[0, 69, 164], [0, 71, 117], etc... ]"
using an object according to the second comment
var arreglo = texto.split(/\r?\n/).map(function(linea){
var numeros = linea.split(' ');
return {user: numeros[0], tecla: numeros[1], time: numeros[2]};
};
var arregloJson = JSON.stringify(arreglo);
notes:
The split(/\r?\n/)
uses a regular expression that separates both Linux lines (separated by \n
) and Windows lines (separated by \r\n
)
The proposed code can also be used on the client side in all current browsers.