I’m extremely new to Make, but have been coding for decades. After a few hours of searching, I have a problem I can’t find an obvious answer for.
My current scenario consists of four modules, in a line:
- Create JSON, which at the moment holds a small amount of static data for testing. This data is in the same structure I expect to receive from an API that will eventually replace the test data
- Parse JSON, which is parsing the test JSON
- Iterator, iterating over the parsed JSON
- Create CSV, which takes the data from the iterator and creates the CSV I need.
The CSV output looks the way I would expect. The trouble I’m having is that I need to add a field to the dataset somewhere in this small chain, prior to generating the CSV. The new field’s value will be derived from one of the fields already in the set, for each line.
What do I need to change here, that would allow me to map an additional field per row/item that wasn’t in the original structure, before I convert the data to CSV?
Hi Katie,
Welcome to the Make community!
There are a couple of ways of doing this in Make.
-
Insert a ‘Set Multiple Variables’ module after the iterator and before the ‘Create CSV’ module. The variables you create in this module can then be selected as column headings in the CSV module.
You’ll need to use inline functions in the ‘Set Multiple Variables’ to set the value for each row based on data in your JSON, or anything else really.
-
Use the ‘Create CSV (advanced)’ module instead of the ‘Create CSV’ module. You’d then need to define your CSV output as a JSON schema (a little counterintuitive, I know!), but it will then let you map values to the CSVs columns, including using inline functions for each column.
The first option is probably the easiest to get started with, but the second option gives you more flexibility; to rename columns, for example.
Let us all know how you get on. And if this solved your problem, please make this as the solution.
Kind regards, Terry.
3 Likes
Aha! Thanks so much, I do believe the Create CSV (advanced) module is the nicest option going forward.
For future people in the same position, the Create CSV (Advanced) module worked perfectly once I had defined the structure for a single CSV line instead of trying to structure the whole document inside a containing object like I had to do with the initial test JSON.
2 Likes