How to parse records of a parent with variable number of children into JSON

I am receiving data from a form with some parent information and a array of children information with variable length. How can I parse the data to get a single JSON string that is something like

{“parent_name”: “Tom”,
“children”: [{“name”: “Mike”},{“name”: “Jane”}]}

I have been able to parse the array into a json string using aggregate to json but I can’t figure out how to insert the json string into the parents json without the children’s json string being escaped as text.

Hey there,

can you share some screenshots of the current setup and the input bundle?

Hi, thanks for responding.

I shall give a simplified example of what I’m trying to achieve. The input bundle coming from an online application is something like this

                "PersonalInformation": {
                            "FamilyName": "Tan",
                            "GivenName": "Sing Show",
                            "DateOfBirth": "1960-08-29",
                            "Occupation": "Retired Teacher",
                            "FamilyBackground": {
                                     "MaritalStatus": {
                                              "Id": "143-2",
                                              "Label": "Married"
                                    },
        
                                    "ChildrenInformation": [
                                      {
                                              "Id": "1haZa0",
                                              "FamilyName": "Tan",
                                              "GivenName": "Jun Jun",
                                              "DateOfBirth": "1989-02-01",
                                              "Gender": {
                                                   "Id": "146-1",
                                                   "Label": "F"
                                              },
                                             "FullName": "Tan Jun Jun",
                                             "Age": 36,
                                             "ItemNumber": 1,
                                      },
                                      {
                                             "Id": "1ziQ2R",
                                             "FamilyName": "Tan",
                                             "GivenName": "May May",
                                             "DateOfBirth": "1992-09-09",
                                             "Gender": {
                                                 "Id": "146-1",
                                                 "Label": "F"
                                             },
                                             "FullName": "Tan May May",
                                             "Age": 33,
                                             "ItemNumber": 2,
                                      }]
                                  }
                            }

The number of children will be different for each form entry and I need to convert some of the data into a JSON string such as shown below as required by an API :

                {“parent_name”: “Tan Sing Show”,
                 "FamilyName": "Tan",
                 "GivenName": "Sing Show",
                 "children”: [{“child_name”: “Tan Jun Jun”,
                               "FamilyName": "Tan",
                               "GivenName": "Jun Jun",
                               "DOB": "1989-02-01",
                              },
                              {"child_name”: “Tan May May”,
                               "FamilyName": "Tan",
                               "GivenName": "May May",
                               "DOB": "1992-09-09",
                              }]
                }

In Make’s Create JSON module a Array attribute can be created for “children” but the number of elements in the Array is fixed while the number of children from the form is variable.

I have tried to generate a JSON for the children using Aggregate to JSON module but there is no way to insert this into the main JSON for the parent as there is no attribute type that accepts raw JSON. Text attribute will cause the children JSON string to be escaped with ""s

Whereas if I set Children to Array attribute and create only 1 item and then Map to the Children’s Aggregate to JSON module, only 1 child’s data was included.

I expected the subsequent items to just follow the same structure. Not sure if I setup 6 items in the array will the module go into error when it can’t map the remaining items when there are less than 6 children.

Welcome to the Make community!

From your screenshot/output bundle, it appears that you have an ARRAY of items. What do you do when you have an array?

“Looping” Through Array Items

When you see an array in your module’s output, think of using an Iterator module.

In this example, this variable is an array of items (collections). You’ll want to map this array in an Iterator module.


Question: Have you tried mapping your array variable into an Iterator module, ran the scenario once, and view the output?

Next,

Combining Bundles Using Aggregators

Every result (item/record) from trigger/iterator/list/search/match modules will output a bundle. This can result in multiple bundles, which then trigger multiple operations in future modules (one operation per bundle). To “combine” multiple bundles into a single variable, you’ll need to use an aggregator of some sort.

Aggregators are modules that accumulate multiple bundles into one single bundle. An example of a commonly-used aggregator module is the Array aggregator module. The next popular aggregator is the Text Aggregator which is very flexible and can apply to many use-cases like building of JSON, CSV, HTML.

You can find out more about the other types of aggregator modules here:

Question: Which is the best aggregator do you think you’ll need for your use-case?

Example

Here is an example of how your scenario could look like:
Screenshot 2025-06-10 140016

Output

This is just an example. Your final solution may or may not look like this depending on your requirements and actual data.

For more information, see “Mapping with arrays” in the Help Centre. You should also do the Make Academy, which also covers the use of Iterators & Aggregators.

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":31,"module":"json:ParseJSON","version":1,"parameters":{"type":""},"mapper":{"json":"{\"PersonalInformation\":{\"FamilyName\":\"Tan\",\"GivenName\":\"Sing Show\",\"DateOfBirth\":\"1960-08-29\",\"Occupation\":\"Retired Teacher\",\"FamilyBackground\":{\"MaritalStatus\":{\"Id\":\"143-2\",\"Label\":\"Married\"},\"ChildrenInformation\":[{\"Id\":\"1haZa0\",\"FamilyName\":\"Tan\",\"GivenName\":\"Jun Jun\",\"DateOfBirth\":\"1989-02-01\",\"Gender\":{\"Id\":\"146-1\",\"Label\":\"F\"},\"FullName\":\"Tan Jun Jun\",\"Age\":36,\"ItemNumber\":1},{\"Id\":\"1ziQ2R\",\"FamilyName\":\"Tan\",\"GivenName\":\"May May\",\"DateOfBirth\":\"1992-09-09\",\"Gender\":{\"Id\":\"146-1\",\"Label\":\"F\"},\"FullName\":\"Tan May May\",\"Age\":33,\"ItemNumber\":2}]}}}"},"metadata":{"designer":{"x":1,"y":-1055,"name":"input bundle"},"parameters":[{"name":"type","type":"udt","label":"Data structure"}]}},{"id":32,"module":"builtin:BasicFeeder","version":1,"parameters":{},"mapper":{"array":"{{31.PersonalInformation.FamilyBackground.ChildrenInformation}}"},"metadata":{"designer":{"x":301,"y":-1055}}},{"id":33,"module":"util:TextAggregator","version":1,"parameters":{"rowSeparator":"other","otherRowSeparator":",","feeder":32},"mapper":{"value":"{\r\n  \"child_name\": \"{{32.FullName}}\",\r\n  \"FamilyName\": \"{{32.FamilyName}}\",\r\n  \"GivenName\": \"{{32.GivenName}}\",\r\n  \"DOB\": \"{{32.DateOfBirth}}\"\r\n}"},"metadata":{"designer":{"x":545,"y":-1055,"name":"Convert Children"},"parameters":[{"name":"rowSeparator","type":"select","label":"Row separator","validate":{"enum":["\n","\t","other"]}},{"name":"otherRowSeparator","type":"text","label":"Separator"}],"advanced":true}},{"id":34,"module":"util:ComposeTransformer","version":1,"parameters":{},"mapper":{"value":"{\r\n  \"parent_name\": \"{{31.PersonalInformation.FamilyName}} {{31.PersonalInformation.GivenName}}\",\r\n  \"FamilyName\": \"{{31.PersonalInformation.FamilyName}}\",\r\n  \"GivenName\": \"{{31.PersonalInformation.GivenName}}\",\r\n  \"children\": [ {{33.text}} ]\r\n}"},"metadata":{"designer":{"x":789,"y":-1056,"name":"Build JSON","messages":[{"category":"last","severity":"warning","message":"A transformer should not be the last module in the route."}]}}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

Hope this helps! Let me know if there are any further questions or issues. P.S.: investing some effort into the tutorials in the Make Academy will save you lots of time and frustration using Make!

@samliew

3 Likes

Thanks for the solution!

I did get to using iterator for children but I fed the output to “Aggregate to JSON” module to form the children JSON string.

I didn’t use a string composer to form the final JSON because there are a lot more items to add than the example given, some with conditional logic, so I was trying to get it done in a JSON parser where each of the items are defined in separate fields.

I guess given the setup of the JSON modules, manually forming the JSON string as you suggested is what has to be done :cry:

1 Like

Or I can use the Compose String module to append children JSON to the parent JSON after using substring() to remove the outer brackets and then wrapping the full string with brackets again. This way I can still manage a complicated structure for the parent.

Thanks again for your help :saluting_face: