looping over JSON Object and insert into query

Hi, I have the following JSON Object and i am trying to insert into the database:

try to find a simple way so loop over and it keeps on inserting and append the messages in the variable:

more important are the values which are inside the data say :
0
1
2
3
4
5
6
7
8 and its nested values

here is the attached JSON

{
   "status":"OK",
   "data":{
      "group_id":1522413460,
      "0":{
         "id":"1522413460-1",
         "customid":"",
         "customid1":"",
         "customid2":"",
         "mobile":"000000000",
         "status":"AWAITED-DLR"
      },
      "1":{
         "id":"1522413460-2",
         "customid":null,
         "customid1":null,
         "customid2":null,
         "mobile":"000000000",
         "status":"AWAITED-DLR"
      },
      "2":{
         "id":"1522413460-3",
         "customid":null,
         "customid1":null,
         "customid2":null,
         "mobile":"000000000",
         "status":"AWAITED-DLR"
      },
      "3":{
         "id":"1522413460-4",
         "customid":null,
         "customid1":null,
         "customid2":null,
         "mobile":"",
         "status":"INV-NUMBER"
      }
   },
   "message":"Campaign of 4 numbers Submitted successfully."
}

Open in new window

LVL 16
Gurpreet Singh RandhawaCEOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mr_NilCommented:
Have you tried using the deserializeJSON function?
0
Mr_NilCommented:
Try this :

<cfsavecontent variable="JSONData">
{
   "status":"OK",
   "data":{
      "group_id":1522413460,
      "0":{
         "id":"1522413460-1",
         "customid":"",
         "customid1":"",
         "customid2":"",
         "mobile":"000000000",
         "status":"AWAITED-DLR"
      },
      "1":{
         "id":"1522413460-2",
         "customid":null,
         "customid1":null,
         "customid2":null,
         "mobile":"000000000",
         "status":"AWAITED-DLR"
      },
      "2":{
         "id":"1522413460-3",
         "customid":null,
         "customid1":null,
         "customid2":null,
         "mobile":"000000000",
         "status":"AWAITED-DLR"
      },
      "3":{
         "id":"1522413460-4",
         "customid":null,
         "customid1":null,
         "customid2":null,
         "mobile":"",
         "status":"INV-NUMBER"
      }
   },
   "message":"Campaign of 4 numbers Submitted successfully."
}
</cfsavecontent>
<cfset jsonstruct = DeserializeJSON(JSONData)>
<cfset mydata.status = jsonstruct.status>
<cfset mydata.message = jsonstruct.message>
<cfset mydata.groupid = jsonstruct.data.group_id>

<cfset mydataKeys = StructKeyList(jsonstruct.data)>
<cfloop list="#mydataKeys#" index="thisKey">
   <cfif IsNumeric(thisKey)>
      <cfoutput>thisKey : #thisKey#</cfoutput>
      <cfdump var="#jsonstruct.data[thisKey]#">
   </cfif>
</cfloop>

Open in new window


This code converts the json data that you give in your question to a structure using deserializeJSON as I suggested. In them gets the keys out of the data and loops around the list of keys and outputs the structure for that key.

cfdump is a great tool for testing and debugging your code.  Definitely worth trying these things before you ask a question.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gurpreet Singh RandhawaCEOAuthor Commented:
i will check today
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.