JSON Splitter for Nested Arrays

This example demonstrates how to use the JSON Splitter Snap to split a nested array in a JSON structure. The pipeline contains a File Reader, JSON Parser, and JSON Splitter Snap.

  1. File Reader Snap reads the JSON file

    The JSON file contains nested arrays under the orders and orderlines keys:

    {
                "customer": "ACME",
                "orders": [
                {
                "ordernumber": "01",
                "orderdate": "20131122",
                "orderlines": [
                { "prod": "p1", "price": "23" },
                { "prod": "p2", "price": "13" },
                { "prod": "p3", "price": "231" }
                ],
                "city": "san mateo"
                },
                {
                "ordernumber": "02",
                "orderdate": "20131222",
                "orderlines": [
                { "prod": "w1", "price": "123" },
                { "prod": "e2", "price": "3" },
                { "prod": "q3", "price": "31" }
                ],
                "city": "burlingame"
                }
                ]
                }
  2. JSON Parser Snap parses the input

    The JSON Parser Snap converts the file contents into structured JSON that can be processed further downstream.

  3. JSON Splitter Snap splits the nested array

    The JSON Splitter Snap is configured with the following JSON path:

    $orders[*].orderlines

    The data output would look something like this:

    [
      {
        "prod": "p1",
        "price": "23",
        "orderdate": "20131122",
        "ordernumber": "01",
        "customer": "ACME",
        "city": "san mateo" },
      {
        "prod": "p2",
        "price": "13",
        "orderdate": "20131122",
        "ordernumber": "01",
        "customer": "ACME",
        "city": "san mateo" },
      {
        "prod": "p3",
        "price": "231",
        "orderdate": "20131122",
        "ordernumber": "01",
        "customer": "ACME",
        "city": "san mateo" },
      {
        "prod": "w1",
        "price": "123",
        "orderdate": "20131222",
        "ordernumber": "02",
        "customer": "ACME",
        "city": "burlingame" },
      {
        "prod": "e2",
        "price": "3",
        "orderdate": "20131222",
        "ordernumber": "02",
        "customer": "ACME",
        "city": "burlingame" },
      {
        "prod": "q3",
        "price": "31",
        "orderdate": "20131222",
        "ordernumber": "02",
        "customer": "ACME",
        "city": "burlingame" }
    ]
     
  1. Ensure the JSON Parser Snap has valid structured output.
  2. Set the JSON Splitter Snap path to $orders[*].orderlines to split each orderlines array.
  3. Use $orders[*].orderlines[*] if you want to split each orderline into separate documents.