Skip to main content
Solved

How to extract list in JSON to Excel file

  • February 17, 2021
  • 2 replies
  • 56 views

Hi,

I have extracted the list in JSON file to an excel file using ListExploder. However the result didn't come out as expected:result 

Any suggestions on which transformer can I use to get the expected result as attached:

Expected 

Thank you in advance.

Best answer by caracadrian

Use ListElementCounter to get the total number of elements, ListExploder to separate into features.

Use AttributeManager to create 4 new attributes (your list appears to have 4 columns) with conditional values: if 

@fmod(@Value(_element_index),4)=0

 than give the first attribute the value of station_info_apims, =1 the second, =2 the third and =3 the fourth.

Than create a fifth attribute that will become the new index with the value:

(@Value(list_count)-@Value(_element_index))/4+@fmod(@Value(_element_index),4)/4

And just use an Aggregator with GroupBy your fifth attribute Mode set to Attributes Only and Accumulation Mode set to Merge Incoming Attributes.

I attached a sample workspace.

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

caracadrian
Contributor
Forum|alt.badge.img+23
  • Contributor
  • 571 replies
  • Best Answer
  • February 17, 2021

Use ListElementCounter to get the total number of elements, ListExploder to separate into features.

Use AttributeManager to create 4 new attributes (your list appears to have 4 columns) with conditional values: if 

@fmod(@Value(_element_index),4)=0

 than give the first attribute the value of station_info_apims, =1 the second, =2 the third and =3 the fourth.

Than create a fifth attribute that will become the new index with the value:

(@Value(list_count)-@Value(_element_index))/4+@fmod(@Value(_element_index),4)/4

And just use an Aggregator with GroupBy your fifth attribute Mode set to Attributes Only and Accumulation Mode set to Merge Incoming Attributes.

I attached a sample workspace.

 


  • Author
  • 10 replies
  • February 17, 2021

Use ListElementCounter to get the total number of elements, ListExploder to separate into features.

Use AttributeManager to create 4 new attributes (your list appears to have 4 columns) with conditional values: if 

@fmod(@Value(_element_index),4)=0

 than give the first attribute the value of station_info_apims, =1 the second, =2 the third and =3 the fourth.

Than create a fifth attribute that will become the new index with the value:

(@Value(list_count)-@Value(_element_index))/4+@fmod(@Value(_element_index),4)/4

And just use an Aggregator with GroupBy your fifth attribute Mode set to Attributes Only and Accumulation Mode set to Merge Incoming Attributes.

I attached a sample workspace.

 

Thank you so much for your answer! I'm new to this FME and your answer really helps me. I will try your solution to resolve this issue.

 

Thanks again!