Support Questions

Find answers, ask questions, and share your expertise

How do I remove the nulls with this jolt?

avatar
New Contributor

Ive got an input that will have different IDs:

 

 

 

{
  "title": "Screening Questions - Questions Test ID 48670",
  "description": "",
  "type": "object",
  "properties": {
    "15": {
      "type": "string",
      "title": "<img src=\"data&colon;image/png;base64,iVBORw0KGgoAAA ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4 //8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU 5ErkJggg==\" alt=\"Red dot\" />",
      "description": ""
    },
    "17": {
      "type": "string",
      "title": "Test ID",
      "description": ""
    },
    "18": {
      "type": "string",
      "title": "Test ID",
      "description": ""
    },
    "19": {
      "type": "string",
      "title": "asdsadsad",
      "description": ""
    }
  },
  "dependencies": [],
  "required": [],
  "av:propertyOrder": [
    15,
    17,
    18,
    19
  ]
}

 

 

And I'm changing it with the following jolt:

 

 

[
  {
    "operation": "shift",
    "spec": {
      "definitions": {
        "optionSet_*": "definitions.&(0,1)",
        "*": "&"
      },
      "*": "&"
    }
  }, {
    "operation": "shift",
    "spec": {
      "properties": {
        "*": {
          // simple match.  Put the value '4' in the output under the "Rating" field
          "title": "Questions[&1].question",
          "type": {
            "number": {
              "#select": "Questions[&3].type"
            },
            "string": {
              "#textarea": "Questions[&3].type"
            },
            "array": {
              "#multiselect": "Questions[&3].type"
            }
          },
          "$": "Questions[&1].id"
        }
      },
      "dependencies": {
        "*": {
          // simple match.  Put the value '4' in the output under the "Rating" field
          "switch": {
            "*": {
              "then": {
                "properties": {
                  "*": {
                    "title": "Questions[&1].question",
                    "type": {
                      "number": {
                        "#select": "Questions[&3].type"
                      },
                      "string": {
                        "#textarea": "Questions[&3].type"
                      },
                      "array": {
                        "#multiselect": "Questions[&3].type"
                      }
                    },
                    "$": "Questions[&1].id"
                  }
                },
                "required": {
                  "*": {
                    "#true": "Questions[@(1)].required"
                  }
                }
              }
            }
          }
        }
      },
      "definitions": {
        "*": {
          "anyOf": {
            "*": {
              "title": "Questions[&3].options[#2].label",
              "const": "Questions[&3].options[#2].value"
            }
          }
        }
      },
      "required": {
        "*": {
          "#true": "Questions[@(1)].required"
        }
      }
    }
    },
  {
    "operation": "remove",
    "spec": {
      "Questions": {
        "0": ""
      }
    }
    },
  {
    "operation": "shift",
    "spec": {
      "Questions": "",
      "*": "&"
    }
  }


]

 

 

which leaves me with the following:

 

 

 

[ null, null, null, null, null, null, null, null, null, null, null, null, null, null, {
  "id" : "15",
  "question" : "<img src=\"data&colon;image/png;base64,iVBORw0KGgoAAA ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4 //8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU 5ErkJggg==\" alt=\"Red dot\" />",
  "type" : "textarea"
}, null, {
  "id" : "17",
  "question" : "Test ID",
  "type" : "textarea"
}, {
  "id" : "18",
  "question" : "Test ID",
  "type" : "textarea"
}, {
  "id" : "19",
  "question" : "asdsadsad",
  "type" : "textarea"
} ]

 

 

 

Any idea how to remove those pesky nulls? Tried with the good ol recursivelysquashnulls but it wont do it... thanks in advance!

 

 

4 REPLIES 4

avatar
Community Manager

@wolfsilver00 Welcome to the Cloudera Community!

To help you get the best possible solution, I have tagged our NiFi experts @SAMSAL @cotopaul @MattWho  who may be able to assist you further.

Please keep us updated on your post, and we hope you find a satisfactory solution to your query.


Regards,

Diana Torres,
Community Moderator


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community:

avatar
New Contributor

Thanks for tagging them! ill be waiting for that answer, have a nice day!

 

avatar
Super Guru

Hi ,

Can you replace the following:

 

{
    "operation": "shift",
    "spec": {
      "properties": {
        "*": {
          // simple match.  Put the value '4' in the output under the "Rating" field
          "title": "Questions[&1].question",
          "type": {
            "number": {
              "#select": "Questions[&3].type"
            },
            "string": {
              "#textarea": "Questions[&3].type"
            },
            "array": {
              "#multiselect": "Questions[&3].type"
            }
          },
          "$": "Questions[&1].id"
        }
      }

with the following spec:

{
    "operation": "shift",
    "spec": {
      "properties": {
        "*": {
          // simple match.  Put the value '4' in the output under the "Rating" field
          "title": "Questions_&1.question",
          "type": {
            "number": {
              "#select": "Questions_&3.type"
            },
            "string": {
              "#textarea": "Questions_&3.type"
            },
            "array": {
              "#multiselect": "Questions_&3.type"
            }
          },
          "$": "Questions_&1.id"
        }
      }
    }
  }
  ,
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "Questions_*": "Questions[]"
    }
  }

 

Reference :

https://stackoverflow.com/questions/70394715/remove-null-from-array-using-jolt

 

If that helps please accept solution.

Thanks

 

 

avatar
Community Manager

@wolfsilver00 Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future. 


Regards,

Diana Torres,
Community Moderator


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community: