Search code examples
csvautoml

Create .jsonl files from .csv


I want to use AutoML, specifically the Entity extraction, however, I'm asked to upload a .jsonl file. I don't know that a .jsonl file is nor how to create it. I only have a .csv file. So, how can I create a .jsonl file from a .csv file? And if that is not possible, how can I create a .jsonl file?


Solution

  • This is JSONlines http://jsonlines.org/

    And you can use Miller (https://github.com/johnkerl/miller). In example if your input CSV is

    fieldOne,FieldTwo
    1,lorem
    2,ipsum
    

    you can run

    mlr --c2j cat input_01.csv >output.json 
    

    to have

    { "fieldOne": 1, "FieldTwo": "lorem" }
    { "fieldOne": 2, "FieldTwo": "ipsum" }
    

    This output is a JSON Lines (one valid JSON object, for each row). If you want a JSON you must add the --jlistwrap flag.

    mlr --c2j --jlistwrap cat input.csv
    

    to have

    [
    { "fieldOne": 1, "FieldTwo": "lorem" }
    ,{ "fieldOne": 2, "FieldTwo": "ipsum" }
    ]