<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Creating a value in json only if the key exists using Jolt in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/380276#M244024</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;, Sorry for the delay,&amp;nbsp;&lt;BR /&gt;Thank you for your solution.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
	"relatedParty": [
		{
			"id": "B2BSmallandMediumBusiness",
			"role": "InstanceConsumerGroup",
			"@referredType": "InstanceConsumerGroup"
		}
	],
	"serviceOrderItem": [
		{
			"id": "0965f63b-db26-4397-b222-190a891838f0",
			"action": "modify",
			"service": {
				"id": "cust",
				"state": "active",
				"supportingService": [
					{
						"id": "e26205f4-e144-4ded-9e64-82ede0b26e99",
						"href": "serviceInventory/v4/service"
					}
					]
			},
			"modifyPath": [
				{
					"op": "add",
					"path": "$.supportingService"
				}
			]
		}
	]
}&lt;/LI-CODE&gt;&lt;P&gt;for the incoming request&amp;nbsp;&lt;SPAN&gt;modifyPath will come outside the service object ,&amp;nbsp;supportingService array will come inside service object. the output should have&amp;nbsp;&lt;SPAN class="hljs-attr"&gt;serviceCharacteristic array inside service object with name and value ( value being the whole array moved from modifyPath in this in case),&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-attr"&gt;"serviceCharacteristic"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
        &lt;SPAN class="hljs-attr"&gt;"name"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"modifyPath"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
        &lt;SPAN class="hljs-attr"&gt;"value"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"[]"&lt;/SPAN&gt;
      &lt;SPAN class="hljs-punctuation"&gt;},&lt;BR /&gt;{ &lt;SPAN class="hljs-attr"&gt;"name"&lt;/SPAN&gt; : &lt;SPAN class="hljs-string"&gt;"supportingService"&lt;/SPAN&gt;, &lt;BR /&gt;&lt;SPAN class="hljs-attr"&gt;"value"&lt;/SPAN&gt; : &lt;SPAN class="hljs-string"&gt;"[]"&lt;/SPAN&gt; &lt;BR /&gt;}&lt;BR /&gt;]&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;like the attached screenshot&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="scoutjohn_0-1701754506232.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/39113iF03F8CED80259672/image-size/medium?v=v2&amp;amp;px=400" role="button" title="scoutjohn_0-1701754506232.png" alt="scoutjohn_0-1701754506232.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The input could change , can also have other arrays that need to be moved into the&amp;nbsp;&lt;SPAN&gt;&lt;SPAN class="hljs-attr"&gt;serviceCharacteristic array, was trying to understand if it is possible to avoid the indexing on&amp;nbsp;serviceCharacteristic in jolt transformation.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Dec 2023 05:35:31 GMT</pubDate>
    <dc:creator>scoutjohn</dc:creator>
    <dc:date>2023-12-05T05:35:31Z</dc:date>
    <item>
      <title>Creating a value in json only if the key exists using Jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379250#M243817</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am new to Jolt, I am trying to transform JSON to a particular format using nifi, where i am moving some objects into another object, I think i am close&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;This is my JSON&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
 &lt;SPAN class="hljs-attr"&gt;"relatedParty"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt;
   &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
     &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"B2BSmallandMedium"&lt;/SPAN&gt;
   &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
 &lt;SPAN class="hljs-punctuation"&gt;]&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
 &lt;SPAN class="hljs-attr"&gt;"serviceOrderItem"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt;
   &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
     &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"e26205f4-e144-4ded-9e64-82ede0b26f4"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
     &lt;SPAN class="hljs-attr"&gt;"action"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"add"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
     &lt;SPAN class="hljs-attr"&gt;"service"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
       &lt;SPAN class="hljs-attr"&gt;"name"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"cust"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
       &lt;SPAN class="hljs-attr"&gt;"state"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"active"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
       &lt;SPAN class="hljs-attr"&gt;"supportingService"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt;
         &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
           &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"e26205f4-e144-4ded-9e64-82ede0b26e99"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
           &lt;SPAN class="hljs-attr"&gt;"href"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"serviceInventory/v4/service"&lt;/SPAN&gt;
         &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
         &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
           &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"7313c885-a075-4188-a6bc-c3fbfb4c7422"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
           &lt;SPAN class="hljs-attr"&gt;"href"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"activationAndConfiguration/v4/service"&lt;/SPAN&gt;
         &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
       &lt;SPAN class="hljs-punctuation"&gt;]&lt;/SPAN&gt;
     &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
   &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
 &lt;SPAN class="hljs-punctuation"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;I am new to Jolt, I am trying to transform JSON to a particular format, where i am moving some objects into another object, I think i am close.&lt;/P&gt;&lt;P&gt;This is my JSON&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
 &lt;SPAN class="hljs-attr"&gt;"relatedParty"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt;
   &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
     &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"B2BSmallandMedium"&lt;/SPAN&gt;
   &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
 &lt;SPAN class="hljs-punctuation"&gt;]&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
 &lt;SPAN class="hljs-attr"&gt;"serviceOrderItem"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt;
   &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
     &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"e26205f4-e144-4ded-9e64-82ede0b26f4"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
     &lt;SPAN class="hljs-attr"&gt;"action"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"add"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
     &lt;SPAN class="hljs-attr"&gt;"service"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
       &lt;SPAN class="hljs-attr"&gt;"name"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"cust"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
       &lt;SPAN class="hljs-attr"&gt;"state"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"active"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
       &lt;SPAN class="hljs-attr"&gt;"supportingService"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt;
         &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
           &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"e26205f4-e144-4ded-9e64-82ede0b26e99"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
           &lt;SPAN class="hljs-attr"&gt;"href"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"serviceInventory/v4/service"&lt;/SPAN&gt;
         &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
         &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
           &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"7313c885-a075-4188-a6bc-c3fbfb4c7422"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
           &lt;SPAN class="hljs-attr"&gt;"href"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"activationAndConfiguration/v4/service"&lt;/SPAN&gt;
         &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
       &lt;SPAN class="hljs-punctuation"&gt;]&lt;/SPAN&gt;
     &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
   &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
 &lt;SPAN class="hljs-punctuation"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;I am using the JOLT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "relatedParty": "relatedParty",
      "serviceOrderItem": {
        "*": {
          "id": "serviceOrderItem[&amp;amp;1].id",
          "action": "serviceOrderItem[&amp;amp;1].action",
          "service": {
            "*": "serviceOrderItem[&amp;amp;2].service.&amp;amp;",
            "#modifyPath": "serviceOrderItem[&amp;amp;2].service.serviceCharacteristic[0].name",
            "@(1,modifyPath)": "serviceOrderItem[&amp;amp;2].service.serviceCharacteristic[0].value",
            "#supportingService": "serviceOrderItem[&amp;amp;2].service.serviceCharacteristic[1].name",
            "@(1,service.supportingService)": "serviceOrderItem[&amp;amp;2].service.serviceCharacteristic[1].value"
          }
        }
      }
    }
},
  {
    "operation": "modify-default-beta",
    "spec": {
      "serviceOrderItem": {
        "*": {
          "service": {
            "serviceCharacteristic": {
              "*": {
                "value": []
              }
            }
          }
        }
      }
    }
},
  {
    "operation": "remove",
    "spec": {
      "serviceOrderItem": {
        "*": {
          "service": {
            "supportingService": ""
          }
        }
      }
    }
}]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is now giving me&lt;/P&gt;&lt;PRE&gt;    &lt;SPAN class="hljs-attr"&gt;"service"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
      &lt;SPAN class="hljs-attr"&gt;"name"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"cust"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
      &lt;SPAN class="hljs-attr"&gt;"serviceCharacteristic"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
        &lt;SPAN class="hljs-attr"&gt;"name"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"modifyPath"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
        &lt;SPAN class="hljs-attr"&gt;"value"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"[]"&lt;/SPAN&gt;
      &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
        &lt;SPAN class="hljs-attr"&gt;"name"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"supportingService"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
        &lt;SPAN class="hljs-attr"&gt;"value"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
          &lt;SPAN class="hljs-attr"&gt;"href"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"serviceInventory/v4/service"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
          &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"e26205f4-e144-4ded-9e64-82ede0b26e99"&lt;/SPAN&gt;
        &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
          &lt;SPAN class="hljs-attr"&gt;"href"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"activationAndConfiguration/v4/service"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
          &lt;SPAN class="hljs-attr"&gt;"id"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"7313c885-a075-4188-a6bc-c3fbfb4c7422"&lt;/SPAN&gt;
        &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;]&lt;/SPAN&gt;
      &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;]&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
      &lt;SPAN class="hljs-attr"&gt;"state"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"active"&lt;/SPAN&gt;
    &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt;
  &lt;SPAN class="hljs-punctuation"&gt;}&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;]&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;This is working for me but,&lt;/P&gt;&lt;P&gt;I would like to know if it is possible replace:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;"#modifyPath": "serviceOrderItem[&amp;amp;2].service.serviceCharacteristic[0].name"&lt;/P&gt;&lt;P&gt;"#supportingService": "serviceOrderItem[&amp;amp;2].service.serviceCharacteristic[1].name"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;to update the Json only when the key is actually available. I do not want an empty array.&lt;/P&gt;&lt;P&gt;Thank you for your time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 03:43:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379250#M243817</guid>
      <dc:creator>scoutjohn</dc:creator>
      <dc:date>2023-11-21T03:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a value in json only if the key exists using Jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379265#M243819</link>
      <description>&lt;P&gt;Changed the jolt to&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "relatedParty": "relatedParty",
      "serviceOrderItem": {
        "*": {
          "id": "serviceOrderItem[&amp;amp;1].id",
          "action": "serviceOrderItem[&amp;amp;1].action",
          "service": {
            "*": "serviceOrderItem[&amp;amp;2].service.&amp;amp;",
            "supportingService": {
              "#supportingService": "serviceOrderItem[&amp;amp;3].service.serviceCharacteristic[1].name",
              "*": "serviceOrderItem[&amp;amp;3].service.serviceCharacteristic[1].value"
            }
          },
          "modifyPath": {
            "#modifyPath": "serviceOrderItem[&amp;amp;2].service.serviceCharacteristic[1].name",
            "@(1,modifyPath)": "serviceOrderItem[&amp;amp;2].service.serviceCharacteristic[1].value"
          }
        }
      }
    }
},
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=recursivelySquashNulls"
    }
  }]&lt;/LI-CODE&gt;&lt;P&gt;Is there a way to remove the indexing from&amp;nbsp;&lt;STRONG&gt;serviceCharacteristic[1].name / serviceCharacteristic[0].name ?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 05:52:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379265#M243819</guid>
      <dc:creator>scoutjohn</dc:creator>
      <dc:date>2023-11-21T05:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a value in json only if the key exists using Jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379791#M243932</link>
      <description>&lt;P&gt;You don't have to put it back into an array [] if you don't want.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 23:54:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379791#M243932</guid>
      <dc:creator>joseomjr</dc:creator>
      <dc:date>2023-11-28T23:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a value in json only if the key exists using Jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379931#M243960</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/105558"&gt;@joseomjr&lt;/a&gt;,&amp;nbsp; Infact i want it in an array, as objects inside serviceCharacteristics array&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if i could avoid the 1 inside serviceCharacteristics[1] rather put a more generic indexing&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 11:50:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379931#M243960</guid>
      <dc:creator>scoutjohn</dc:creator>
      <dc:date>2023-11-30T11:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a value in json only if the key exists using Jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379941#M243965</link>
      <description>&lt;P&gt;A gotcha, you can do what you already do in your JOLT and use &amp;amp; instead of using 1&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 15:07:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379941#M243965</guid>
      <dc:creator>joseomjr</dc:creator>
      <dc:date>2023-11-30T15:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a value in json only if the key exists using Jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379943#M243967</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/97154"&gt;@scoutjohn&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;Your spec can be written as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "*": "&amp;amp;",
      "serviceOrderItem": {
        "*": {
          "*": "serviceOrderItem.[&amp;amp;1].&amp;amp;",
          "service": {
            "*": "serviceOrderItem.[&amp;amp;2].service.&amp;amp;",
            "supportingService": {
              "$": "serviceOrderItem.[&amp;amp;3].service.serviceCharacteristic[#].name",
              "@": "serviceOrderItem.[&amp;amp;3].service.serviceCharacteristic[#].value"
            }
          }
        }
      }
    }
  }]&lt;/LI-CODE&gt;&lt;P&gt;I did not not add the&amp;nbsp; "modifyPath" because I did not see anything related to this object in the provided json input.&lt;/P&gt;&lt;P&gt;Notice how I used # for serviceCharacteristic[#].name &amp;amp; serviceCharacteristic[#].value which tells the spec to group everything under one object under the&amp;nbsp;serviceCharacteristic array.&lt;/P&gt;&lt;P&gt;If you find this helpful please &lt;STRONG&gt;accept&lt;/STRONG&gt; solution.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 15:32:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/379943#M243967</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2023-11-30T15:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a value in json only if the key exists using Jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/380276#M244024</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;, Sorry for the delay,&amp;nbsp;&lt;BR /&gt;Thank you for your solution.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
	"relatedParty": [
		{
			"id": "B2BSmallandMediumBusiness",
			"role": "InstanceConsumerGroup",
			"@referredType": "InstanceConsumerGroup"
		}
	],
	"serviceOrderItem": [
		{
			"id": "0965f63b-db26-4397-b222-190a891838f0",
			"action": "modify",
			"service": {
				"id": "cust",
				"state": "active",
				"supportingService": [
					{
						"id": "e26205f4-e144-4ded-9e64-82ede0b26e99",
						"href": "serviceInventory/v4/service"
					}
					]
			},
			"modifyPath": [
				{
					"op": "add",
					"path": "$.supportingService"
				}
			]
		}
	]
}&lt;/LI-CODE&gt;&lt;P&gt;for the incoming request&amp;nbsp;&lt;SPAN&gt;modifyPath will come outside the service object ,&amp;nbsp;supportingService array will come inside service object. the output should have&amp;nbsp;&lt;SPAN class="hljs-attr"&gt;serviceCharacteristic array inside service object with name and value ( value being the whole array moved from modifyPath in this in case),&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-attr"&gt;"serviceCharacteristic"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;[&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;{&lt;/SPAN&gt;
        &lt;SPAN class="hljs-attr"&gt;"name"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"modifyPath"&lt;/SPAN&gt;&lt;SPAN class="hljs-punctuation"&gt;,&lt;/SPAN&gt;
        &lt;SPAN class="hljs-attr"&gt;"value"&lt;/SPAN&gt; &lt;SPAN class="hljs-punctuation"&gt;:&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;"[]"&lt;/SPAN&gt;
      &lt;SPAN class="hljs-punctuation"&gt;},&lt;BR /&gt;{ &lt;SPAN class="hljs-attr"&gt;"name"&lt;/SPAN&gt; : &lt;SPAN class="hljs-string"&gt;"supportingService"&lt;/SPAN&gt;, &lt;BR /&gt;&lt;SPAN class="hljs-attr"&gt;"value"&lt;/SPAN&gt; : &lt;SPAN class="hljs-string"&gt;"[]"&lt;/SPAN&gt; &lt;BR /&gt;}&lt;BR /&gt;]&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;like the attached screenshot&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="scoutjohn_0-1701754506232.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/39113iF03F8CED80259672/image-size/medium?v=v2&amp;amp;px=400" role="button" title="scoutjohn_0-1701754506232.png" alt="scoutjohn_0-1701754506232.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The input could change , can also have other arrays that need to be moved into the&amp;nbsp;&lt;SPAN&gt;&lt;SPAN class="hljs-attr"&gt;serviceCharacteristic array, was trying to understand if it is possible to avoid the indexing on&amp;nbsp;serviceCharacteristic in jolt transformation.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 05:35:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/380276#M244024</guid>
      <dc:creator>scoutjohn</dc:creator>
      <dc:date>2023-12-05T05:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a value in json only if the key exists using Jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/380283#M244028</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/97154"&gt;@scoutjohn&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I can see the full problem now. I wish I have considered it in my first response because it will change things a little bit.&lt;/P&gt;&lt;P&gt;Since you have mentioned that you could have other arrays in each level, the current spec basically wont work unless you create different specs for different scenarios which is not a good idea.&lt;/P&gt;&lt;P&gt;This can be resolved in two shift transformations:&lt;/P&gt;&lt;P&gt;1- Bring those array objects from different levels&amp;nbsp; into "serviceCharacteristic" array.&lt;/P&gt;&lt;P&gt;2- Apply the name, value assignment based on each object array index in "serviceCharacteristic" array.&lt;/P&gt;&lt;P&gt;In this case no need to figure out how many arrays objects you might have in the each level, nor you have to assign hard coded index.&lt;/P&gt;&lt;P&gt;Here is the final spec:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  // First transformation, group array objects under service
  // and serviceOrderItem into one array "serviceCharacteristic"
  {
    "operation": "shift",
    "spec": {
      "*": "&amp;amp;",
      "serviceOrderItem": {
        "*": {
          "id": "serviceOrderItem.[&amp;amp;1].&amp;amp;",
          "action": "serviceOrderItem.[&amp;amp;1].&amp;amp;",
          "service": {
            "id": "serviceOrderItem.[&amp;amp;2].service.&amp;amp;",
            "state": "serviceOrderItem.[&amp;amp;2].service.&amp;amp;",
            //group any array objects at the supportingService level into serviceCharacteristic
            "*": "serviceOrderItem.[&amp;amp;2].service.serviceCharacteristic[].&amp;amp;"
          },
          //group any array objects at the modifyPath level into serviceCharacteristic
          "*": "serviceOrderItem.[&amp;amp;1].service.serviceCharacteristic[].&amp;amp;"
        }
      }
    }
  },
  // 2ed transformation to assign name, value for each
  // serviceCharacteristic array object
  {
    "operation": "shift",
    "spec": {
      "*": "&amp;amp;",
      "serviceOrderItem": {
        "*": {
          "*": "serviceOrderItem.[&amp;amp;1].&amp;amp;",
          "service": {
            "*": "serviceOrderItem.[&amp;amp;2].service.&amp;amp;",
            "serviceCharacteristic": {
              "*": {
                "*": {
                  "$": "serviceOrderItem.[&amp;amp;5].service.serviceCharacteristic[&amp;amp;2].name",
                  "@": "serviceOrderItem.[&amp;amp;5].service.serviceCharacteristic[&amp;amp;2].value"
                }
              }
            }
          }
        }
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: Not sure why you need the "recursivelySquashNulls"&amp;nbsp; transformation. I did not see any use case for here but you can add it if it solves other issues.&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 11:49:56 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/380283#M244028</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2023-12-05T11:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a value in json only if the key exists using Jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/380296#M244031</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;, Thank you. this works.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="scoutjohn_0-1701780207080.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/39118i53CD29ABD5667837/image-size/medium?v=v2&amp;amp;px=400" role="button" title="scoutjohn_0-1701780207080.png" alt="scoutjohn_0-1701780207080.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 12:43:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Creating-a-value-in-json-only-if-the-key-exists-using-Jolt/m-p/380296#M244031</guid>
      <dc:creator>scoutjohn</dc:creator>
      <dc:date>2023-12-05T12:43:34Z</dc:date>
    </item>
  </channel>
</rss>

