arraysjsonapache-nifitransformationjolt

Null elements when filling a JSON array using JOLT v0.1.1


I'm trying to fill a JSON array from a JSON input using a JOLT v0.1.1 transformation. But I'm having the problem that the array is filled with null elements before the elements I want to include.

This is the input:

{
  "data": {
    "type": "applications",
    "id": "664caa6588bf5100sdfsdf078bb060",
    "attributes": {
      "appliedAt": 1716300389,
      "completedAt": 1716300607,
      "status": "new",
      "progress": {
        "all": 12,
        "completed": 12
      },
      "matchingScore": 48,
      "language": "en-GB",
      "matchingProfile": {
        "bracketId": "poor",
        "label": "Poor Fit"
      }
    },
    "relationships": {
      "candidate": {
        "data": {
          "type": "candidates",
          "id": "664caa6588bf5100078bb060",
          "email": "atest+9@test.net",
          "attributes": {
            "firstName": "test",
            "lastName": "test",
            "email": "test@test.net"
          }
        }
      },
      "vacancy": {
        "data": {
          "type": "vacancies",
          "id": "65bd009dde98c00007e0e7b4"
        }
      },
      "report": {
        "data": {
          "type": "reports",
          "id": "1716300609586aco_REPORT.pdf"
        }
      },
      "fact-sheets": {
        "data": {
          "type": "fact-sheeto_FACT_SHEET.pdf"
        }
      },
      "candidate-detail-page": {
        "data": {
          "type": "candidate-detail-page",
          "id": "664caa6588bf5100078bb060"
        }
      },
      "matching-results": {
        "data": [
          {
            "type": "matching-results",
            "id": "664caa6588bf5100078bb060-65bcfffd74158f00070d5a96"
          },
          {
            "type": "matching-results",
            "id": "664caa6588bf5100078bb060-65bd0023de98c00007e0e6a8"
          },
          {
            "type": "matching-results",
            "id": "664caa6588bf5100078bb060-65bd006cde98c00007e0e6fa"
          },
          {
            "type": "matching-results",
            "id": "664caa6588bf5100078bb060-65bd007f74158f00070d5b0f"
          },
          {
            "type": "matching-results",
            "id": "664caa6588bf5100078bb060-65c6263974b26da67537703d"
          }
        ]
      },
      "matching-indicators": {
        "data": [
          {
            "type": "matching-indicators",
            "id": "65bd128774158f00070d67bd"
          },
          {
            "type": "matching-indicators",
            "id": "65bd129c74158f00070d67d4"
          },
          {
            "type": "matching-indicators",
            "id": "65bd133fde98c00007e0fa12"
          },
          {
            "type": "matching-indicators",
            "id": "65bd1463de98c00007e0fa9d"
          }
        ]
      },
      "personal-information": {
        "data": {
          "type": "personal-information",
          "id": "65bcfff5de98c00007e0e64b"
        }
      }
    }
  },
  "included": [
    {
      "type": "reports",
      "id": "1716300609586agustin_braco_REPORT.pdf",
      "attributes": {
        "expiresAt": 1716390988,
        "url": "https:ludGVncmF0aW9uLnRyYW5zY29tZW1lYQ=="
      }
    },
    {
      "type": "fact-sheets",
      "id": "1716300609489agustin_braco_FACT_SHEET.pdf",
      "attributes": {
        "expiresAt": 1716390988,
        "url": "https://edHeaders=host"
      }
    },
    {
      "type": "candidate-detail-page",
      "id": "664caa6588bf5100078bb060",
      "attributes": {
        "url": "https://100078bb060"
      }
    },
    {
      "type": "matching-results",
      "id": "664caa6588bf5100078bb060-65bcfffd74158f00070d5a96",
      "attributes": {
        "moduleType": "PersonalityPrintModule",
        "calculatedAt": 1716300607,
        "moduleScore": 0,
        "moduleWeight": 0
      },
      "relationships": {
        "module": {
          "data": {
            "type": "modules",
            "id": "65bcfffd74158f00070d5a96"
          }
        }
      },
      "meta": {
        "dimensionScores": {
          "agreeableness": {
            "percentile": 5.7,
            "rawScore": 3.5
          },
          "assertiveness": {
            "percentile": 91.14,
            "rawScore": 4.333333333333333
          },
          "empathy": {
            "percentile": 23.9,
            "rawScore": 4.125
          },
          "followThrough": {
            "percentile": 61.3,
            "rawScore": 5
          },
          "learningFocused": {
            "percentile": 81.05,
            "rawScore": 5
          },
          "multitasking": {
            "percentile": 18,
            "rawScore": 3
          },
          "organization": {
            "percentile": 0.01,
            "rawScore": 2.25
          },
          "preferenceForDirection": {
            "percentile": 0.01,
            "rawScore": 2.25
          },
          "resilience": {
            "percentile": 77.82,
            "rawScore": 5.166666666666667
          },
          "sociability": {
            "percentile": 84.81,
            "rawScore": 5
          },
          "workIntensity": {
            "percentile": 4.3,
            "rawScore": 3.142857142857143
          }
        },
        "normGroup": "europe",
        "variant": "short"
      }
    },
    {
      "type": "matching-results",
      "id": "664caa6588bf5100078bb060-65bd0023de98c00007e0e6a8",
      "attributes": {
        "moduleType": "NOAModule",
        "calculatedAt": 1716300607,
        "moduleScore": 0,
        "moduleWeight": 0
      },
      "relationships": {
        "module": {
          "data": {
            "type": "modules",
            "id": "65bd0023de98c00007e0e6a8"
          }
        }
      },
      "meta": {
        "components": [
          {
            "normGroup": "medium",
            "score": 0,
            "type": "NOA Exclusion"
          }
        ]
      }
    },
    {
      "type": "matching-results",
      "id": "664caa6588bf5100078bb060-65bd006cde98c00007e0e6fa",
      "attributes": {
        "moduleType": "LanguageTestModule",
        "calculatedAt": 1716300607,
        "moduleScore": 16.333333333333332,
        "moduleWeight": 0
      },
      "relationships": {
        "module": {
          "data": {
            "type": "modules",
            "id": "65bd006cde98c00007e0e6fa"
          }
        }
      },
      "meta": {
        "grading": "<B2",
        "sectionScores": [
          {
            "name": "vocabulary",
            "score": 13
          },
          {
            "name": "grammar",
            "score": 20
          },
          {
            "name": "comprehension",
            "score": 16
          }
        ]
      }
    },
    {
      "type": "matching-results",
      "id": "664caa6588bf5100078bb060-65bd007f74158f00070d5b0f",
      "attributes": {
        "moduleType": "JobKnowledgeTestModule",
        "calculatedAt": 1716300607,
        "moduleScore": 0,
        "moduleWeight": 0
      },
      "relationships": {
        "module": {
          "data": {
            "type": "modules",
            "id": "65bd007f74158f00070d5b0f"
          }
        }
      },
      "meta": {
        "scoresByQuestionId": {
          "0daeeeb4-eabd-4b64-9f0f-7d01fb09bf08": 0,
          "2dba74a2-d527-4c65-a734-2d6017355ac3": 0,
          "3bbe3045-6a74-463a-8242-8f8b1ae778c7": 0,
          "3db7a0c7-0027-4836-8208-475e41009d56": 0,
          "613592b8-6b95-4e55-ac87-2dc3d08f92c7": 0,
          "68a710b6-ac2b-4986-90e2-5d14695d3405": 0,
          "6c331725-12f0-4ebd-8282-37a1361771d8": 0,
          "8156b45b-6c4f-469d-8698-902e6cc12400": 0,
          "8a1c0138-3f57-42d0-bbf7-4c6f577ab5a9": 0,
          "bee5f06f-7353-4de7-b078-4ce17fa58542": 0
        }
      }
    },
    {
      "type": "matching-results",
      "id": "664caa6588bf5100078bb060-65c6263974b26da67537703d",
      "attributes": {
        "moduleType": "SituationalJudgmentTestModule",
        "calculatedAt": 1716300607,
        "moduleScore": 41.66666666666667,
        "moduleWeight": 0
      },
      "relationships": {
        "module": {
          "data": {
            "type": "modules",
            "id": "65c6263974b26da67537703d"
          }
        }
      },
      "meta": {
        "pointsPerQuestion": {
          "026c7707-7f0e-43ef-bfc0-c165f6a1e5e2": {
            "points": -1,
            "score": 25
          },
          "5a4922e4-b15d-4e5f-9fb7-566ee88b7a9c": {
            "points": 1,
            "score": 75
          },
          "a0052eaa-fc4f-4235-b5d4-77209c79e0db": {
            "points": -1,
            "score": 25
          }
        }
      }
    },
    {
      "type": "ats-parameters",
      "attributes": {
        "candidateId": "395303",
        "jobId": "893",
        "createdBy": "api"
      }
    },
    {
      "type": "matching-indicators",
      "id": "65bd128774158f00070d67bd",
      "attributes": {
        "name": "Logical Reasoning",
        "score": 0,
        "bracketId": "poor",
        "externalId": "",
        "fail": false,
        "label": "Poor Fit",
        "brackets": [
          {
            "bracketId": "good",
            "cutoff": false,
            "name": "Good Fit",
            "treshold": 40
          },
          {
            "bracketId": "great",
            "cutoff": false,
            "name": "Great Fit",
            "treshold": 66
          }
        ]
      }
    },
    {
      "type": "matching-indicators",
      "id": "65bd129c74158f00070d67d4",
      "attributes": {
        "name": "English Proficiency",
        "score": 16,
        "bracketId": "poor",
        "externalId": "",
        "fail": false,
        "label": "Below B2",
        "brackets": [
          {
            "bracketId": "good",
            "cutoff": false,
            "name": "B2 and above",
            "treshold": 66
          }
        ]
      }
    },
    {
      "type": "matching-indicators",
      "id": "65bd133fde98c00007e0fa12",
      "attributes": {
        "name": "Customer Support Personality V2TEST",
        "score": 57,
        "bracketId": "poor",
        "externalId": "",
        "fail": false,
        "label": "Poor Fit",
        "brackets": [
          {
            "bracketId": "good",
            "cutoff": false,
            "name": "Good Fit",
            "treshold": 65
          },
          {
            "bracketId": "great",
            "cutoff": false,
            "name": "Great Fit",
            "treshold": 80
          }
        ]
      }
    },
    {
      "type": "matching-indicators",
      "id": "65bd1463de98c00007e0fa9d",
      "attributes": {
        "name": "Situational Judgement Test",
        "score": 42,
        "bracketId": "good",
        "externalId": "",
        "fail": false,
        "label": "Good Fit",
        "brackets": [
          {
            "bracketId": "good",
            "cutoff": false,
            "name": "Good Fit",
            "treshold": 40
          },
          {
            "bracketId": "great",
            "cutoff": false,
            "name": "Great Fit",
            "treshold": 80
          }
        ]
      }
    }
  ]
}

I just need an array of elements that contain the name, the label and the score of every element of the 'included' array in which "type":"matching-indicators".

JOLT:

[
  {
    "operation": "shift",
    "spec": {
      "included": {
        "*": {
          "type": {
            "matching-indicators": {
              "@2,attributes": {
                "name|score|label": "[&4].&"
              }
            }
          }
        }
      }
    }
  }
]

I also used this one:

[
  {
    "operation": "shift",
    "spec": {
      "included": {
        "*": {
          "attributes": {
            "name": "[&2].name",
            "label": "[&2].label",
            "score": "[&2].score"
          }
        }
      }
    }
  }
]

Expected output:

[
  {
    "name": "Logical Reasoning",
    "score": 0,
    "label": "Poor Fit"
  },
  {
    "name": "English Proficiency",
    "score": 16,
    "label": "Below B2"
  },
  {
    "name": "Customer Support Personality V2TEST",
    "score": 57,
    "label": "Poor Fit"
  },
  {
    "name": "Situational Judgement Test",
    "score": 42,
    "label": "Good Fit"
  }
]

Obtained output:

[
  null,
  null,
  null,
  null,
  null,
  null,
  null,
  null,
  null,
  {
    "name": "Logical Reasoning",
    "score": 0,
    "label": "Poor Fit"
  },
  {
    "name": "English Proficiency",
    "score": 16,
    "label": "Below B2"
  },
  {
    "name": "Customer Support Personality V2TEST",
    "score": 57,
    "label": "Poor Fit"
  },
  {
    "name": "Situational Judgement Test",
    "score": 42,
    "label": "Good Fit"
  }
]

In short, I need the array that I am obtaining, but without the null elements that appear at the beginning of it.


Solution

  • The generation of nulls is due to some type attributes those don't match the value matching-indicators and [&<int>] type identifiers expect indexes starts from zero and go without gaps like 0,1,2,3 ... to be able to prevent null generation, So, prefer &<int> type identifiers within a spec, and then nest whole content with square brackets within the upcoming spec and get the array of objects without key values such as

    [
      {
        "operation": "shift",
        "spec": {
          "included": {
            "*": {
              "type": {
                "matching-indicators": {
                  "@2,attributes": {
                    "name|score|label": "&4.&"
                  }
                }
              }
            }
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "*": "[]"
        }
      }
    ]