Creating A JSON Object with a Conditionally Undefined Key / Value Pair

First off, I love this tool as it’s been so helpful for me in both professional environments for testing as well as in my own personal projects so thank you so much for creating something so versatile!

My problem is that I’m trying to create a conditional key / value pair in my JSON object that is dependent upon a secret key / value pair… and I’m failing miserably.

Presently my object looks like this:

{
  "externalPatientChartId": 12345,
  "patientName": "Frame, Abbie Burke",
  "tenantId": 697190,
  "orderType": "SUPPLIES",
  "nameDescription": "Routine Home Care",
  "createdAction": {
    "actionType": "CREATED",
    "userId": 744405,
    "username": "auto@mation.com",
    "displayName": "AutoMation",
    "datetime": "2023-02-13T20:11:14Z",
    "timezone": "America/Chicago"
  },
  "modifiedAction": {
    "actionType": null,
    "userId": null,
    "username": null,
    "displayName": null,
    "datetime": null,
    "timezone": null
  },
  "patientChartId": 54321,
  "isOrderModified": "0",
  "ifOrderModifiedWhatActionTaken": ""
}

"isOrderModified" is just showing what my secret "__isOrderModified" key / value pair has been set to. Presently my object has the following formula for all of the key / value pairs within "modifiedAction":

if field("__isOrderModified") == 0 then generate("Blank") else this end

66% of the time the "modifiedAction" key / value pair is going to be present, but for the other 34% of the time, the "modifiedAction" key shouldn’t be present in the larger JSON object - in essence making the object look like this:

{
  "externalPatientChartId": 12345,
  "patientName": "Frame, Abbie Burke",
  "tenantId": 697190,
  "orderType": "SUPPLIES",
  "nameDescription": "Routine Home Care",
  "createdAction": {
    "actionType": "CREATED",
    "userId": 744405,
    "username": "auto@mation.com",
    "displayName": "AutoMation",
    "datetime": "2023-02-13T20:11:14Z",
    "timezone": "America/Chicago"
  },
  // modifiedAction key has been removed / is undefined
  "patientChartId": 54321,
  "isOrderModified": "0",
  "ifOrderModifiedWhatActionTaken": ""
}

How do I go about getting Mockaroo to exhibit this behavior? Any guidance you can offer would be very much appreciated!

I figured it out! There’s a helpful little checkbox that is included called include null values which - when unchecked - removes null values from the return which is exactly what I’m looking for. Sorry for bogging down your message board but thank you for thinking ahead in having a feature that solves my problem! Cheers!