github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/types/jsonl.md (about)

     1  # `jsonl`
     2  
     3  > JSON Lines
     4  
     5  ## Description
     6  
     7  The following description is taken from [jsonlines.org](http://jsonlines.org/):
     8  
     9  > JSON Lines is a convenient format for storing structured data that may be
    10  > processed one record at a time. It works well with unix-style text
    11  > processing tools and shell pipelines. It's a great format for log files.
    12  > It's also a flexible format for passing messages between cooperating
    13  > processes.
    14  
    15  ## Examples
    16  
    17  Example JSON lines documents taken from [jsonlines.org](http://jsonlines.org/examples/)
    18  
    19  ### Tabulated data
    20  
    21  ```
    22  ["Name", "Session", "Score", "Completed"]
    23  ["Gilbert", "2013", 24, true]
    24  ["Alexa", "2013", 29, true]
    25  ["May", "2012B", 14, false]
    26  ["Deloise", "2012A", 19, true] 
    27  ```
    28  
    29  This format is equatable to `generic` and `csv`.
    30  
    31  ### Nested objects
    32  
    33  ```
    34  {"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]}
    35  {"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]}
    36  {"name": "May", "wins": []}
    37  {"name": "Deloise", "wins": [["three of a kind", "5♣"]]}
    38  ```
    39  
    40  ## Detail
    41  
    42  ### Concatenated JSON
    43  
    44  Technically the `jsonl` Unmarshal() method supports Concatenated JSON, as
    45  described on [Wikipedia](https://en.wikipedia.org/wiki/JSON_streaming#Concatenated_JSON):
    46  
    47  > Concatenated JSON streaming allows the sender to simply write each JSON
    48  > object into the stream with no delimiters. It relies on the receiver using
    49  > a parser that can recognize and emit each JSON object as the terminating
    50  > character is parsed. Concatenated JSON isn't a new format, it's simply a
    51  > name for streaming multiple JSON objects without any delimiters.
    52  >
    53  > The advantage of this format is that it can handle JSON objects that have
    54  > been formatted with embedded newline characters, e.g., pretty-printed for
    55  > human readability. For example, these two inputs are both valid and produce
    56  > the same output:
    57  >
    58  > #### Single line concatenated JSON
    59  >
    60  >     {"some":"thing\n"}{"may":{"include":"nested","objects":["and","arrays"]}}
    61  >
    62  > #### Multi-line concatenated JSON
    63  >
    64  >     {
    65  >       "some": "thing\n"
    66  >     }
    67  >     {
    68  >       "may": {
    69  >         "include": "nested",
    70  >         "objects": [
    71  >           "and",
    72  >           "arrays"
    73  >         ]
    74  >       }
    75  >     }
    76  
    77  ...however in Murex's case, only single line concatenated JSON files
    78  (example 1) are supported; and that is only supported to cover some edge
    79  cases when writing JSON lines and a new line character isn't included. The
    80  primary example might be when generating JSON lines from inside a `for` loop.
    81  
    82  This is resolved in the new data-type parser `jsonc` (Concatenated JSON). See
    83  line below.
    84  
    85  ### More information
    86  
    87  This format is sometimes also referred to as LDJSON and NDJSON, as described
    88  on [Wikipedia](https://en.wikipedia.org/wiki/JSON_streaming#Line-delimited_JSON).
    89  
    90  Murex's [`json` data-type document](json.md) also describes some use
    91  cases for JSON lines.
    92  
    93  ## Default Associations
    94  
    95  * **Extension**: `json-lines`
    96  * **Extension**: `jsonl`
    97  * **Extension**: `jsonlines`
    98  * **Extension**: `ldjson`
    99  * **Extension**: `murex_history`
   100  * **Extension**: `ndjson`
   101  * **MIME**: `application/json-lines`
   102  * **MIME**: `application/jsonl`
   103  * **MIME**: `application/jsonlines`
   104  * **MIME**: `application/ldjson`
   105  * **MIME**: `application/ndjson`
   106  * **MIME**: `application/x-json-lines`
   107  * **MIME**: `application/x-jsonl`
   108  * **MIME**: `application/x-jsonlines`
   109  * **MIME**: `application/x-ldjson`
   110  * **MIME**: `application/x-ndjson`
   111  * **MIME**: `text/json-lines`
   112  * **MIME**: `text/jsonl`
   113  * **MIME**: `text/jsonlines`
   114  * **MIME**: `text/ldjson`
   115  * **MIME**: `text/ndjson`
   116  * **MIME**: `text/x-json-lines`
   117  * **MIME**: `text/x-jsonl`
   118  * **MIME**: `text/x-jsonlines`
   119  * **MIME**: `text/x-ldjson`
   120  * **MIME**: `text/x-ndjson`
   121  
   122  
   123  ## Supported Hooks
   124  
   125  * `Marshal()`
   126      Supported
   127  * `ReadArray()`
   128      Works with JSON arrays. Maps are converted into arrays
   129  * `ReadArrayWithType()`
   130      Works with JSON arrays. Maps are converted into arrays. Element data type is `json` 
   131  * `ReadIndex()`
   132      Works against all properties in JSON
   133  * `ReadMap()`
   134      Not currently supported.
   135  * `ReadNotIndex()`
   136      Works against all properties in JSON
   137  * `Unmarshal()`
   138      Supported
   139  * `WriteArray()`
   140      Supported
   141  
   142  ## See Also
   143  
   144  * [`*` (generic)](../types/generic.md):
   145    generic (primitive)
   146  * [`[[ Element ]]`](../parser/element.md):
   147    Outputs an element from a nested structure
   148  * [`cast`](../commands/cast.md):
   149    Alters the data type of the previous function without altering it's output
   150  * [`csv`](../types/csv.md):
   151    CSV files (and other character delimited tables)
   152  * [`foreach`](../commands/foreach.md):
   153    Iterate through an array
   154  * [`format`](../commands/format.md):
   155    Reformat one data-type into another data-type
   156  * [`hcl`](../types/hcl.md):
   157    HashiCorp Configuration Language (HCL)
   158  * [`json`](../types/json.md):
   159    JavaScript Object Notation (JSON)
   160  * [`jsonc`](../types/jsonc.md):
   161    Concatenated JSON
   162  * [`open`](../commands/open.md):
   163    Open a file with a preferred handler
   164  * [`pretty`](../commands/pretty.md):
   165    Prettifies JSON to make it human readable
   166  * [`runtime`](../commands/runtime.md):
   167    Returns runtime information on the internal state of Murex
   168  * [`toml`](../types/toml.md):
   169    Tom's Obvious, Minimal Language (TOML)
   170  * [`yaml`](../types/yaml.md):
   171    YAML Ain't Markup Language (YAML)
   172  * [index](../parser/item-index.md):
   173    Outputs an element from an array, map or table
   174  * [mxjson](../types/mxjson.md):
   175    Murex-flavoured JSON (deprecated)
   176  
   177  ### Read more about type hooks
   178  
   179  - [`ReadIndex()` (type)](../apis/ReadIndex.md): Data type handler for the index, `[`, builtin
   180  - [`ReadNotIndex()` (type)](../apis/ReadNotIndex.md): Data type handler for the bang-prefixed index, `![`, builtin
   181  - [`ReadArray()` (type)](../apis/ReadArray.md): Read from a data type one array element at a time
   182  - [`WriteArray()` (type)](../apis/WriteArray.md): Write a data type, one array element at a time
   183  - [`ReadMap()` (type)](../apis/ReadMap.md): Treat data type as a key/value structure and read its contents
   184  - [`Marshal()` (type)](../apis/Marshal.md): Converts structured memory into a structured file format (eg for stdio)
   185  - [`Unmarshal()` (type)](../apis/Unmarshal.md): Converts a structured file format into structured memory
   186  
   187  <hr/>
   188  
   189  This document was generated from [builtins/types/jsonlines/jsonlines_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/types/jsonlines/jsonlines_doc.yaml).