= 1024) leftSidebarOpen = false; if(window.innerWidth >= 1280) rightSidebarOpen = false"<br>:class="{ 'dark': $store.theme.dark, 'left-sidebar-closed': !leftSidebarDesktop, 'right-sidebar-closed': !rightSidebarDesktop, 'overflow-hidden': leftSidebarOpen || rightSidebarOpen, 'sidebars-closed': !leftSidebarDesktop && !rightSidebarDesktop }">
How to Import JSON into MongoDB and Export to CSV with Data Masking
Skip to content
Navigation
if (window.innerWidth
Preferences
Layout
Save Sidebar view
Remember if sidebars are open or closed across pages.
Save Sidebar layout preference
Enable Bookmarks
Save your favourite articles locally in this browser.
Enable Local Bookmarks
let scroll = window.scrollY;<br>let docHeight = document.documentElement.scrollHeight - window.innerHeight;<br>this.progress = docHeight > 0 ? Math.max(0, Math.min(1, scroll / docHeight)) : 0;<br>this.ticking = false;<br>});<br>}"<br>@scroll.window.passive="update()"<br>@resize.window.passive="update()"<br>x-init="update()"<br>class="fixed top-0 left-0 w-full h-[3px] z-[100] pointer-events-none">
Automating a MongoDB JSON import, collection update, and masked CSV export in VisuaLeaf Task Manager.
Every morning, an online store receives the previous day’s orders from a marketplace partner.<br>The file comes in JSON format. The company needs to add those orders to its main MongoDB orders collection. The sales manager also needs a CSV report that can be opened in Excel.<br>That sounds like a small task. Import the file, copy the documents, export the report.<br>But in practice, a few things can break the process.<br>A date can be imported as a string. A field can have the wrong name. One batch may use total, while the main collection uses totalAmount. A temporary collection can keep old records and trigger duplicate key errors. A CSV export can create null values because the mapping points to fields that do not exist.<br>And then there is customer data. The manager may need the sales numbers, but they probably do not need real customer names or internal customer IDs.<br>This article walks through a real daily workflow:<br>Import marketplace JSON<br>Store the batch in a temporary MongoDB collection<br>Copy the orders into the main orders collection<br>Mask customer fields during export<br>Create a CSV report<br>The goal is not just to move data from JSON to CSV. The goal is to make the process repeatable, easier to check, and safer to share.<br>VisuaLeaf Task Manager runs the import, copy, and CSV export jobs in order.The workflow<br>The workflow has three jobs:<br>Import Yesterday Orders<br>Add Orders to Main<br>Export Daily Sales ReportThe important part is the parent relationship between the jobs.<br>Add Orders to Main depends on Import Yesterday Orders, so it only runs after the JSON file is imported successfully.<br>Export Daily Sales Report depends on Add Orders to Main, so the CSV is created only after the main orders collection has been updated.<br>This prevents the report from being generated when data is missing or incomplete.<br>Parent jobs keep the import, copy, and CSV export running in the correct order.The incoming JSON file<br>The partner sends a file with yesterday’s completed orders.<br>A single order looks like this:<br>"orderId": "ORD-2026-07-201",<br>"customerId": "CUST-1003",<br>"customerName": "Sofia Rossi",<br>"orderDate": "2026-07-21T08:20:00Z",<br>"status": "completed",<br>"paymentStatus": "paid",<br>"currency": "EUR",<br>"items": [<br>"sku": "EL-002",<br>"productName": "Wireless Mouse",<br>"category": "Electronics",<br>"quantity": 1,<br>"unitPrice": 24.99,<br>"lineTotal": 24.99<br>},<br>"sku": "EL-003",<br>"productName": "Mechanical Keyboard",<br>"category": "Electronics",<br>"quantity": 1,<br>"unitPrice": 79.99,<br>"lineTotal": 79.99<br>],<br>"itemsSummary": "1x Wireless Mouse, 1x Mechanical Keyboard",<br>"itemCount": 2,<br>"subtotal": 104.98,<br>"discount": 10,<br>"shippingFee": 4.99,<br>"totalAmount": 99.97,<br>"couponCode": "WELCOME10"<br>There are two fields worth pointing out here.<br>The first is items. This is the real order structure. It keeps each product as a nested object with its own SKU, quantity, price, and line total.<br>The second is itemsSummary. This is not as rich as the items array, but it works better in a CSV report. Instead of putting a full JSON array into one spreadsheet cell, the manager sees a readable value:<br>1x Wireless Mouse, 1x Mechanical Keyboard<br>MongoDB handles nested arrays well. CSV does not. So for the database, keep the array. For the report, export the summary.<br>The first job imports the file into a temporary collection:<br>online_store.daily_sales_import<br>The import job loads the marketplace JSON file into a temporary MongoDB collection.Why use a temporary collection?<br>The first job imports the JSON file into online_store.daily_sales_import instead of writing directly to orders.<br>This extra step is worth it.<br>The file comes from another system. Even if the partner usually sends the correct structure, a single change can break your report. A field can be renamed. A value can arrive as text instead of a number. A date can be formatted differently. Or the import job can...