nodered teaser.png

Export JSON to CSV format using Node-RED in ctrlX OS

KatjaX
Community Manager
Community Manager
Content

For every work using JSON objects or file type, we seldom come across scenarios when we have to convert it into a CSV (Comma Separated Values) format. This is very much possible on ctrlX CORE when working with Node-RED.

Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click. Learn more about  Node-RED (external page).

Requirements
Steps to perform
  1. Open your ctrlX OS console in the browser. You will be directed to the homepage. There, click on Manage app data.
  2. In the Manage app data page click on the Node-RED configuration in the Content table.
     Manage app data screenManage app data screen 
  3. Once you have accessed the Node-RED configurations folder, you will observe many files that are associated to the Node-RED installed in your ctrlX OS. You can add a folder/directory here which will be used in the Node-RED. This data can be easily imported from your local machine or can even be created using the Create File option under Creates Directory or file option at the top right corner with as shown in the image below. For this demonstration we have created a daten folder which will have a sample.json file having a dummy json object.

    Node-RED configuration directoryNode-RED configuration directory 

    Sample json fileSample json file

  4. Once we are setup with our data, we will open the Node-RED flow editor. In the editor we use the following nodes as shown in the image below. 
    1. Common > inject node
    2. Storage > read file
    3. Parser > JSON
    4. Parser > CSV
    5. Storage > write File
    6. Common > debug (Optional- to test the output of the flow in debugger)
       Complete flow of Node-REDComplete flow of Node-RED
  5. We use the inject as a trigger for the flow using the timestamp. In the read file node we use the file location "solutions/activeConfiguration/node-RED/daten/sample.json" to read the data. Please change the directory name as per your requirement.
  6. In the JSON node, set Action to Always convert to Javascript Object to properly parse your JSON file. 
  7. Next we connect JSON node to the CSV node. In the CSV node you can specify the column names in the input box of Columns field. You can also leave it blank for the node to parse the column names automatically.
  8. We are now ready to connect our final node, i.e. the write file node which will save the CSV into the required folder. In the demonstration we have saved the file in the same folder as the input data. You can select the "Create directory if it doesn't exist?" option so as to create a directory in case not already created and is not same as the input data directory.
    Note: Add the full path to your file to be saved along with the destination file name and extension.
    Voila! We are set to test our flow.
  9. Once we deploy the flow and click on the trigger node of the flow, the JSON file is fetched >> parsed by the JSON node >> converted into CSV >> stored in the destination folder.
Related Information
AyushX
AyushX
Editorial work by: KatjaX
Must Read
Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist