function saveAsJSONL(data, name=new Date().toLocaleString('sv').replace(' ','T').replaceAll(':','_')+'.jsonl') {
const a = document.createElement('a')
a.download = name
a.href = URL.createObjectURL(new Blob([data.map(JSON.stringify).join('\n')], {type: 'application/jsonlines+json'}))
a.click()
}
JavaScriptのデータを保存する
Usage
saveAsJSONL(['pen', 'pineapple', 'apple', 'pen'])
// ファイル名を指定
saveAsJSONL(['pen', 'pineapple', 'apple', 'pen'], 'hoge.jsonl')
Pythonでデータを読み込む
import pandas as pd
pd.read_json('hoge.jsonl', lines=True)
JavaScriptでデータを読み込む
const url = 'https://gist.githubusercontent.com/GitHub30/7599230721e390ec51345f7db3e930db/raw/4ebb3c648499200593e84315c362105008d01869/hoge.jsonl'
const array = await fetch(url).then(r=>r.text()).then(text => text.split('\n').map(JSON.parse))
console.log(array)
See the Pen Untitled by John Doe (@04) on CodePen.
参考