最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - Need a jolt spec to populate a field along with condition check for the same field - Stack Overflow

programmeradmin1浏览0评论

Need a jolt spec with only the mentioned field in output section.remaining fields are not required.As "date" is the field for which I need to populate the output json also need to check "date" is null or not depending on "type" we need to populate. I wrote the jolt which is only population either "date" or "type", but i need both

If inventory.release.date is not null, then "type":"ReleaseDate" If date is not present then check if inventory.release.days is not null or not 0 , then "type":"PriorToArrival"

Input json:

{
  "inventory": {
    "release": {
      "date": "2025-01-16",
      "days": 0,
      "isRolling": true,
       "value": "4gh",
       "computationType": "Flat"
    }
  }
}

Output json:

{
  "releaseSettings": {
    "date": "2025-01-16",
    "type":"ReleaseDate",
    "isRolling": true
  }
}

Need a jolt spec with only the mentioned field in output section.remaining fields are not required.As "date" is the field for which I need to populate the output json also need to check "date" is null or not depending on "type" we need to populate. I wrote the jolt which is only population either "date" or "type", but i need both

If inventory.release.date is not null, then "type":"ReleaseDate" If date is not present then check if inventory.release.days is not null or not 0 , then "type":"PriorToArrival"

Input json:

{
  "inventory": {
    "release": {
      "date": "2025-01-16",
      "days": 0,
      "isRolling": true,
       "value": "4gh",
       "computationType": "Flat"
    }
  }
}

Output json:

{
  "releaseSettings": {
    "date": "2025-01-16",
    "type":"ReleaseDate",
    "isRolling": true
  }
}
Share Improve this question asked Feb 10 at 18:13 OptimizerOptimizer 2611 gold badge2 silver badges10 bronze badges 1
  • 1 yes. it will be and not or. It is working and Thanks for your help. – Optimizer Commented Feb 12 at 7:21
Add a comment  | 

1 Answer 1

Reset to default 1

I assume that you want to chack if inventory.release.days is not null and not 0 rather, then you can use the following transformation :

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "inventory": {
        "release": {
          "typeChk": ["=isPresent(@(1,date))", "PriorToArrival"] //set to "PriorToArrival" if "date" attribute doesn't exist
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "inventory": {
        "release": {
          "date|isRolling": "&1Settings.&",
          "typeChk": {
            "PriorToArrival": {
              "@2,days": {
                "0": {
                  "": ""
                },
                "*": { //if the value of "days" > 0
                  "@3": "&5Settings.type"
                }
              }
            },
            "*": { //if not set to "PriorToArrival" within the modify spec
              "#ReleaseDate": "&3Settings.type"
            }
          }
        }
      }
    }
  }
]
发布评论

评论列表(0)

  1. 暂无评论