0

First time post, so please pardon my format. Will try to provide as much detail as I can. I'm using CF 2018 and receiving a JSON file with data around employees. I can handle the API call to get it, but need some advice on how to best process it.

Here's the JSON file:

{
  "Report_Entry": [
    {
       "Account_Group": "HEALTH GROUP",
       "Group": "SERVICES GROUP",
       "Employee_ID": "111111",
       "Legal_Name_-_First_Name": "Ted",
       "Worker_Skills_as_Text": "Programmer",
       "Certification": "ICAgile Certified Professional (ICP) - The International Consortium for Agile",
       "primaryWorkEmail": "ted_smith@abc.com"
    },
    {
       "Account_Group": "FINANCE GROUP",
       "Group": "INNOVATION TEAM",
       "Employee_ID": "222222",
       "Legal_Name_-_First_Name": "Mary",
       "Worker_Skills_as_Text": "Analyst",
       "Certification": "PMP; Writing Master",
       "primaryWorkEmail": "mary_smith@abc.com"
    },
    {
       "Account_Group": "ENERGY GROUP",
       "Group": "BUSINESS DEVELOPMENT TEAM",
       "Employee_ID": "333333",
       "Legal_Name_-_First_Name": "John",
       "Worker_Skills_as_Text": "Developer",
       "Certification": "Certified Scrum Master (CSM) - Scrum Alliance; Certified Scrum Product Owner (CSPO) - Scrum Alliance",
       "primaryWorkEmail": "john_smith@abc.com"
    }
  ]
}

When I deserialize it returns as as:

enter image description here

I need to be able to loop through the structure, arrays, and the structure to capture the values then process them (i.e., insert into a table, compare to existing data, etc.). I know I need to loop through the entire thing but can't come up with the right syntax with error.

Any help or examples would be greatly appreciated.

Thanks

Jim

rrk
  • 15,677
  • 4
  • 29
  • 45
Jim
  • 1
  • 2
    What have you tried til now? Please add the code you tried with to loop/filter the data. – rrk May 20 '20 at 17:24
  • 3
    Hint : You already have an array of *structures*. Loop through that array to get each structure. Access the values using the various key names, like `yourStruct.Employee_ID`. – SOS May 20 '20 at 19:24
  • Does this answer your question? https://stackoverflow.com/questions/61918143/how-to-return-in-struct-with-my-cfoutput – James A Mohler May 21 '20 at 22:30

1 Answers1

1

Here is what I've been using for dealing with something similar:

Based on your dump, you have a struct with an array of structs.

the following is a snippet that should return the first element of the array, which is a struct:

 myStruct = Report_entry[1];
                         for (currentKey in myStruct) {
                                writedump(currentKey);
                                writedump(myStruct[currentKey]);
                                writeoutput('<hr>');
}

you want to get the syntax of looping over arrays and looping over structs.

CFDUMP is your friend.


I'd be happy to help with syntax. I recognize I did not provide a complete solution, but you are a little closer.

squizzler
  • 11
  • 4