0

I have an object called jsonJobsOpen and when I dump it the output shows the value for this Object as shown below.

[{
    "APPLICATIONCOUNT":0,
    "JOBNAME":"Candidate Migration Job ",
    "JOBID":"15433AAE-8631-FA8B-AEA7-49E116EF60E1 ",
    "JOBCLOSEDATE":" ",
    "JOBSTATUSLABELVALUE":"Incomplete",
    "ENCRYPTEDURLAPPCOUNT":"event=cms.listApplicantsPersistVars&JobID=15433AAE-8631-FA8B-AEA7-49E116EF60E1&JobAppStatusID=DCA85CD5-A134-7A4B-30E8-49E116F0D702",
    "JOBOPENDATE":" ",
    "APPLIEDAPPCOUNT":0,
    "JOBSTATUSLABELCOLOUR":"D8605F",
    "REFERENCE":"Candidate Migration Job ",
    "ENCRYPTEDURL":"event=jm.gotoJCW&JobID=15433AAE-8631-FA8B-AEA7-49E116EF60E1",
    "ENCRYPTEDURLCANDIDATEASSESSMENT":"event=jm.gotoJCW&JobID=15433AAE-8631-FA8B-AEA7-49E116EF60E1",
    "ENCRYPTEDURLAPPLICANTLIST":"event=cms.listApplicantsPersistVars&JobID=15433AAE-8631-FA8B-AEA7-49E116EF60E1"
}]

If there is no value associated with Object then the dump looks like this:

[{
    "JOBID":"",
    "JOBOPENDATE":"",
    "JOBCLOSEDATE":"",
    "JOBNAME":"",
    "REFERENCE":"",
    "ENCRYPTEDURL":"",
    "APPLICATIONCOUNT":"",
    "ENCRYPTEDURLAPPLICANTLIST":"",
    "ENCRYPTEDURLCANDIDATEASSESSMENT":"",
    "JOBSTATUSLABELVALUE":"",
    "JOBSTATUSLABELCOLOUR":"",
    "APPLIEDAPPCOUNT":"",
    "ENCRYPTEDURLAPPCOUNT":""
}]

My question here is what condition can I use to check if the value is there or not with this object in ColdFusion?

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
abhi kumar
  • 35
  • 5

1 Answers1

2

From Leigh's answer here

In JSON, the [] denotes an array and {} a structure (or object). So your input is actually an array of structures. You need to use an array loop ...

<cfset arrayOfStructs = deserializeJson(jsonJobsOpen)>
<cfloop array="#arrayOfStructs#" index="thisValue">
    <!--- Now you can use this condition to check for empty values --->
    <cfif StructKeyExists(thisValue, "JOBID") and Len(thisValue.JOBID) GT 0>
    ... 
</cfloop>

I'm doing a couple things there. First deserializing the JSON string into something ColdFusion can handle (an array of structures). Then checking that the JOBID field exists. If it does exist, then also check that it's length is greater than 0 (not empty).

You should be able to do something like this for each element (assuming that the name of your variable containing this JSON is jsonJobsOpen.

Here is a quick ColdFusion Gist that shows an example using your data.

Community
  • 1
  • 1
Miguel-F
  • 13,450
  • 6
  • 38
  • 63