cancel
Showing results for 
Search instead for 
Did you mean: 

Handling Multiple 'null values

aditya_gupta41
Contributor

I am currently having this requirement where i need to handle all the null values coming in input. The common thing i noticed that all these values end with ‘_DATE’ but this is coming in an object. for all the null values, i need to pass value ‘0000-00-00’. The challenge which i am facing is this is dynamic. sometimes there are overall 28 fields ending with ‘_DATE’ and sometimes its more than 100.

[
  {
  "DEPRECIATIONAREAS": [
      {
        "ASSET": "00005000xxxx",
        "DEP_UNITS": 0,
        "O_START_DATE": "2006-09-01",
        "S_START_DATE": null,
        "INTEREST_START_DATE": null,
        "READINESS": "2006-08-31",
        "INDEX": "",
        "AGE_INDEX": "",
        "VAR_DEP_PORTION": 0.0000,
        "SCRAPVALUE": 0.0000,
		}
		]
	"POSTINGINFORMATION": [
      {
        "ASSET": "000050009142",
        "SUBNUMBER": "0000",
        "CAP_DATE": "2006-08-31",
        "DEACT_DATE": null,
        "INITIAL_ACQ": "2006-08-31",
        "INITIAL_ACQ_YR": 2006,
        "INITIAL_ACQ_PRD": 11,
        "PLRET_DATE": null,
        "PO_DATE": null,
        "CAP_KEY": ""
		}
		]
		}
		]

Can someone provide me a solution for this?

Thanks in Advance

1 ACCEPTED SOLUTION

This works. Thanks for your help @j.angelevski

View solution in original post

14 REPLIES 14

Hi @aditya.gupta41

I updated the expression, please refer to the following one:

{}.extend(...$data.entries().map(val => typeof val[1] == "object" ? ({val[0]]: val[1].mapValues((v, k) => k.contains("_DATE") && v == null ? "0000-00-00" : v})) : {[val[0]]: val[1].map(v => {}.extend(...v.entries().map(date => date[0].contains("_DATE") && date[1] == null ? {[date[0]]: "0000-00-00"} : {[date[0]]: date[1]} )))}))

Or this one ( with match operator 😞

{}.extend(...$data.entries().map(val =>
	match typeof val[1] {
		"object" =>
				{
					[val[0]]: val[1].mapValues((v, k) => k.contains("_DATE") && v == null ? "0000-00-00" : v)
				},
		"array" =>
				{
					[val[0]]: val[1].map(v => {}.extend(...v.entries().map(date => date[0].contains("_DATE") && date[1] == null ? {[date[0]]: "0000-00-00"} : {[date[0]]: date[1]} )))
				}
	}
))

This works. Thanks for your help @j.angelevski

bojanvelevski
Valued Contributor

Try this:

$data.mapValues((v,k)=>v.map(x=>x.mapValues((v1,k1)=>k1.endsWith("_DATE") && v1 == null ? "0000-00-00" : v1 )))

This too is getting error:

failure:

“Map type does not have a method named: map, found in: …-00-00” : v1 )). Perhaps you meant: mapKeys, mapValues"

Well, that means that the fields TIMEDEPENDENTDATA,SELECTIONCRITERIA, etc. are objects, not arrays like in the sample you sent.