• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Get JSON file to be a Structure of Arrays vs of a structure containing an an array of structures

Participant ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

So I am trying to convert my JSON into a cfquery object to use it in my application.

Here is what my JSON looks like. Its a structure containing an array of structures. 
tempsnip.png

 

But when I look at other CF posts on this topic I see the JSON data looks like this.
A Structure of Arrays. Which there is a lot of documentation on how to work within cf.  
Capture2.PNG

QUESTION: How do I get my deserialized JSON file to be a Structure of Arrays instead of a structure containing an array of structures

Views

2.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 06, 2020 May 06, 2020

I'm sorry.. been a while since I tried any of this, and the flag is actually FALSE, not true.

 

https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-c-d/DeserializeJSON.html

 

If Strictmapping is set to false and the JSON object was created from a CF query object, then DeserializeJSON() will automatically convert the JSON to a CF query object.

 

SO, create a query object from scratch, SerializeJSON() it, then stringify it (I know how in JavaScript, not CF) and look at the f

...

Votes

Translate

Translate
LEGEND ,
May 06, 2020 May 06, 2020

Copy link to clipboard

Copied

It depends upon how it was created.

 

If the JSON object was created from a CF query object, and if a certain flag was set to 'true', then it's just a matter of deserializing it back into a query object.

 

If, however, it was not done with the true flag, or if it was created from a source other than CF (like a third-party API), then check the stringified format of the JSON object and compare it to the stringified format of a JSON object created by CF with the true flag set, and manually edit the other one to match.  Then you could convert it back into a query object.

 

I know that's not exactly the answer you were looking for, but just something to consider.

 

V/r,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 06, 2020 May 06, 2020

Copy link to clipboard

Copied

Thank you, Wolf. This JSON was created by a Google API. I'll try what you suggest. Any idea where I can get a stringified format of a JSON object created by CF with the true flag set?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 06, 2020 May 06, 2020

Copy link to clipboard

Copied

I'm sorry.. been a while since I tried any of this, and the flag is actually FALSE, not true.

 

https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-c-d/DeserializeJSON...

 

If Strictmapping is set to false and the JSON object was created from a CF query object, then DeserializeJSON() will automatically convert the JSON to a CF query object.

 

SO, create a query object from scratch, SerializeJSON() it, then stringify it (I know how in JavaScript, not CF) and look at the format.  If the format of the API JSON string doesn't match, you can take that string and programmatically edit it to match what the CF version is.  CF will then convert the JSON into a CF query object.  I've done it once, but that was about five years ago, and I'm not currently recalling much detail from that project.

 

HTH,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

LATEST

Thanks for marking my answer as correct.  I do appreciate it.

 

So this did what you were looking for?  How'd it go?

 

V/r,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation