JSON generation

Hello, I have a csv File that I want to convert to JSON.
Attached is the format of my csv file.
I want the output to be a JSON of the following format :

[
{
“Code magasin”: 1628,
“Rayons”: [
{
“Nom Rayon”: “EPICERIE”,
“Produits”: [
{
“Code magasin”: 1628,
“Nom Rayon”: “EPICERIE”,
“Nombre de produits”: 3604,
“Couverture Prévision 1”: “83,297,063”,
“Couverture Prévision 2”: “93,163,375”
}
]
},
{
“Nom Rayon”: “FRAIS”,
“Produits”: [
{
“Code magasin”: 1628,
“Nom Rayon”: “FRAIS”,
“Nombre de produits”: 725,
“Couverture Prévision 1”: “96,207,126”,
“Couverture Prévision 2”: “101,167,498”
}
]
}
]
},
{
“Code magasin”: 5070,
“Rayons”: [
{
“Nom Rayon”: “EPICERIE”,
“Produits”: [
{
“Code magasin”: 5070,
“Nom Rayon”: “EPICERIE”,
“Nombre de produits”: 4524,
“Couverture Prévision 1”: “89,916,123”,
“Couverture Prévision 2”: “95,437,706”
}
]
},
{
“Nom Rayon”: “FRAIS”,
“Produits”: [
{
“Code magasin”: 5070,
“Nom Rayon”: “FRAIS”,
“Nombre de produits”: 1125,
“Couverture Prévision 1”: “97,645,316”,
“Couverture Prévision 2”: “98,463,264”
}
]
}
]
},
{
“Code magasin”: 5202,
“Rayons”: [
{
“Nom Rayon”: “EPICERIE”,
“Produits”: [
{
“Code magasin”: 5202,
“Nom Rayon”: “EPICERIE”,
“Nombre de produits”: 3043,
“Couverture Prévision 1”: “9,021,529”,
“Couverture Prévision 2”: “89,220,993”
}
]
},
{
“Nom Rayon”: “FRAIS”,
“Produits”: [
{
“Code magasin”: 5202,
“Nom Rayon”: “FRAIS”,
“Nombre de produits”: 783,
“Couverture Prévision 1”: “105,048,366”,
“Couverture Prévision 2”: “99,020,751”
}
]
}
]
},
{
“Code magasin”: 5481,
“Rayons”: [
{
“Nom Rayon”: “EPICERIE”,
“Produits”: [
{
“Code magasin”: 5481,
“Nom Rayon”: “EPICERIE”,
“Nombre de produits”: 4567,
“Couverture Prévision 1”: “83,747,804”,
“Couverture Prévision 2”: “100,169,735”
}
]
},
{
“Nom Rayon”: “FRAIS”,
“Produits”: [
{
“Code magasin”: 5481,
“Nom Rayon”: “FRAIS”,
“Nombre de produits”: 1085,
“Couverture Prévision 1”: “100,367,242”,
“Couverture Prévision 2”: “109,176,319”
}
]
}
]
},
{
“Code magasin”: 5722,
“Rayons”: [
{
“Nom Rayon”: “EPICERIE”,
“Produits”: [
{
“Code magasin”: 5722,
“Nom Rayon”: “EPICERIE”,
“Nombre de produits”: 3295,
“Couverture Prévision 1”: “87,940,103”,
“Couverture Prévision 2”: “96,538,969”
}
]
},
{
“Nom Rayon”: “FRAIS”,
“Produits”: [
{
“Code magasin”: 5722,
“Nom Rayon”: “FRAIS”,
“Nombre de produits”: 586,
“Couverture Prévision 1”: “94,759,155”,
“Couverture Prévision 2”: “101,164,675”
}
]
}
]
}
]

Do you have any suggestions ?
Thank you

Welcome to the Make community!

Yes, that is possible. You’ll need a minimum of six modules:

The complexity (operations) formula is 2N + 4 , where N = number of code groups.

Hope this helps! Let me know if there are any further questions or issues.

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block

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

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

Click to Expand Module Export Code

JSON - Copy and Paste this directly in the scenario editor

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 174,
                    "module": "csv:ParseCSV",
                    "version": 1,
                    "parameters": {
                        "colCount": null,
                        "csvContainsHeaders": true,
                        "delimiterType": "other",
                        "relax": false,
                        "delimiter": ","
                    },
                    "mapper": {
                        "csv": "Code magasin,Nom Rayon,Nombre de produits,Couverture Prévision 1,Couverture Prévision 2\n5202,EPICERIE,3043,\"9,021,529\",\"89,220,993\"\n5202,FRAIS,783,\"105,048,366\",\"99,020,751\"\n1628,EPICERIE,3604,\"83,297,063\",\"93,163,375\"\n1628,FRAIS,725,\"96,207,126\",\"101,167,498\""
                    },
                    "metadata": {
                        "designer": {
                            "x": 2748,
                            "y": -3271
                        },
                        "restore": {
                            "parameters": {
                                "delimiterType": {
                                    "label": "Other"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "colCount",
                                "type": "number",
                                "label": "Number of columns"
                            },
                            {
                                "name": "csvContainsHeaders",
                                "type": "boolean",
                                "label": "CSV contains headers",
                                "required": true
                            },
                            {
                                "name": "delimiterType",
                                "type": "select",
                                "label": "Delimiter",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        ",",
                                        "\t",
                                        "other"
                                    ]
                                }
                            },
                            {
                                "name": "relax",
                                "type": "boolean",
                                "label": "Preserve quotes inside unquoted field",
                                "required": true
                            },
                            {
                                "name": "delimiter",
                                "type": "text",
                                "label": "Delimiter character",
                                "validate": {
                                    "max": 1,
                                    "min": 1
                                },
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "csv",
                                "type": "text",
                                "label": "CSV",
                                "required": true
                            }
                        ],
                        "interface": [
                            {
                                "name": "col1",
                                "label": "Code magasin",
                                "type": "text"
                            },
                            {
                                "name": "col2",
                                "label": "Nom Rayon",
                                "type": "text"
                            },
                            {
                                "name": "col3",
                                "label": "Nombre de produits",
                                "type": "text"
                            },
                            {
                                "name": "col4",
                                "label": "Couverture Prévision 1",
                                "type": "text"
                            },
                            {
                                "name": "col5",
                                "label": "Couverture Prévision 2",
                                "type": "text"
                            }
                        ]
                    }
                },
                {
                    "id": 175,
                    "module": "builtin:BasicAggregator",
                    "version": 1,
                    "parameters": {
                        "feeder": 174
                    },
                    "mapper": {
                        "col1": "{{174.col1}}",
                        "col2": "{{174.col2}}",
                        "col3": "{{174.col3}}",
                        "col4": "{{174.col4}}",
                        "col5": "{{174.col5}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 2990,
                            "y": -3270,
                            "name": "Group By Code"
                        },
                        "restore": {
                            "extra": {
                                "feeder": {
                                    "label": "CSV - Parse CSV [174]"
                                },
                                "target": {
                                    "label": "Custom"
                                }
                            }
                        },
                        "advanced": true
                    },
                    "flags": {
                        "groupBy": "{{174.col1}}"
                    }
                },
                {
                    "id": 177,
                    "module": "builtin:BasicFeeder",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "array": "{{175.array}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 3235,
                            "y": -3273,
                            "name": "Iterate Rayons"
                        },
                        "restore": {
                            "expect": {
                                "array": {
                                    "mode": "edit"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "array",
                                "type": "array",
                                "label": "Array",
                                "mode": "edit",
                                "spec": []
                            }
                        ]
                    }
                },
                {
                    "id": 178,
                    "module": "util:TextAggregator",
                    "version": 1,
                    "parameters": {
                        "rowSeparator": "other",
                        "otherRowSeparator": ",",
                        "feeder": 177
                    },
                    "mapper": {
                        "value": "{\n  \"Nom Rayon\": \"{{177.col2}}\",\n  \"Produits\": [\n    {\n      \"Code magasin\": {{177.col1}},\n      \"Nom Rayon\": \"{{177.col2}}\",\n      \"Nombre de produits\": \"{{177.col3}}\",\n      \"Couverture Prévision 1\": \"{{177.col4}}\",\n      \"Couverture Prévision 2\": \"{{177.col5}}\"\n    }\n  ]\n}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 3482,
                            "y": -3274,
                            "name": "Aggregate Rayons"
                        },
                        "restore": {
                            "parameters": {
                                "rowSeparator": {
                                    "label": "Other"
                                }
                            },
                            "extra": {
                                "feeder": {
                                    "label": "Iterate Rayons [177]"
                                }
                            },
                            "flags": {
                                "groupBy": {
                                    "collapsed": true
                                },
                                "stopIfEmpty": {
                                    "collapsed": true
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "rowSeparator",
                                "type": "select",
                                "label": "Row separator",
                                "validate": {
                                    "enum": [
                                        "\n",
                                        "\t",
                                        "other"
                                    ]
                                }
                            },
                            {
                                "name": "otherRowSeparator",
                                "type": "text",
                                "label": "Separator"
                            }
                        ],
                        "expect": [
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "advanced": true
                    }
                },
                {
                    "id": 176,
                    "module": "util:TextAggregator",
                    "version": 1,
                    "parameters": {
                        "rowSeparator": "other",
                        "otherRowSeparator": ",",
                        "feeder": 175
                    },
                    "mapper": {
                        "value": "{\n  \"Code magasin\": {{175.`__IMTKEY__`}},\n  \"Rayons\": [\n    {{178.text}}\n  ]\n}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 3728,
                            "y": -3275,
                            "name": "Aggregate Code"
                        },
                        "restore": {
                            "parameters": {
                                "rowSeparator": {
                                    "label": "Other"
                                }
                            },
                            "extra": {
                                "feeder": {
                                    "label": "Array aggregator [175]"
                                }
                            },
                            "flags": {
                                "groupBy": {
                                    "collapsed": true
                                },
                                "stopIfEmpty": {
                                    "collapsed": true
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "rowSeparator",
                                "type": "select",
                                "label": "Row separator",
                                "validate": {
                                    "enum": [
                                        "\n",
                                        "\t",
                                        "other"
                                    ]
                                }
                            },
                            {
                                "name": "otherRowSeparator",
                                "type": "text",
                                "label": "Separator"
                            }
                        ],
                        "expect": [
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "advanced": true
                    }
                },
                {
                    "id": 180,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "json",
                        "scope": "roundtrip",
                        "value": "[{{176.text}}]"
                    },
                    "metadata": {
                        "designer": {
                            "x": 3971,
                            "y": -3277,
                            "name": "Build JSON"
                        },
                        "restore": {
                            "expect": {
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Variable name",
                                "required": true
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            },
                            {
                                "name": "value",
                                "type": "any",
                                "label": "Variable value"
                            }
                        ],
                        "interface": [
                            {
                                "name": "json",
                                "label": "json",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

Hope this helps! Let me know if there are any further questions or issues.

2 Likes

Thank you so much.
I have one more question, when I use my csv file in the CSV PARSER module the names of columns disappear. The output names are col1, col2,…
How can I keep the original column names ?

I have no idea, I think it’s a bug with the CSV module.

For technical issues or bugs like this, directly contacting support can often lead to a faster resolution. They have access to your specific account details, scenario and scenario logs, server-side logs, and internal tools and resources, which allows them to investigate more thoroughly than what you have access to. Additionally, sharing sensitive information about your account or scenario might not be suitable for an open forum discussion.

You can open a new ticket here, or if you are unable to login for some reason, you can create another new free account to access the ticketing system (which is only available to logged-in users). Alternatively, you should be able to send an email to helpdesk@make.com and support@make.com and it should create a ticket. After submitting a new ticket, you will receive an automatic confirmation email with the subject “Ticket Created” in the subject. If you do not receive this, try sending the ticket again.

If you manage to get your issue resolved with support, we’d still love to hear about it! Sharing your solution on the forum can help others facing similar problems.

Hope this helps! Let me know if there are any further questions or issues.

1 Like