• Latest
MuleSoft DataWeave: Reading From the File

MuleSoft DataWeave: Reading From the File

January 20, 2022
S.T.A.L.K.E.R. 2 Development Has Reportedly Resumed Following Its Pause Due to Ukraine Invasion

S.T.A.L.K.E.R. 2 Development Has Reportedly Resumed Following Its Pause Due to Ukraine Invasion

May 23, 2022
Soulvars Fatal Error, Bokura, and the 13th Month Announced for Mobile – TouchArcade

Soulvars Fatal Error, Bokura, and the 13th Month Announced for Mobile – TouchArcade

May 23, 2022
Prehistoric Planet: How to watch the new dinosaur docuseries

Prehistoric Planet: How to watch the new dinosaur docuseries

May 23, 2022
Harry Potter: Magic Awakened and Everything Else Featured at NetEase Connect 2022

Harry Potter: Magic Awakened and Everything Else Featured at NetEase Connect 2022

May 23, 2022
Magic: The Gathering Returns to Dungeons & Dragons – See a New Card!

Magic: The Gathering Returns to Dungeons & Dragons – See a New Card!

May 23, 2022
Comparing Distributed Databases – DZone Database

Comparing Distributed Databases – DZone Database

May 23, 2022
Data Security Considerations in CDWs

Data Security Considerations in CDWs

May 23, 2022
Xiaomi officially announces partnership with Leica, first jointly developed phone arrives in July

Xiaomi officially announces partnership with Leica, first jointly developed phone arrives in July

May 23, 2022
Basic Convolutional Neural Network Architectures

Basic Convolutional Neural Network Architectures

May 23, 2022
Configuring a Shopify MuleSoft Connector

Configuring a Shopify MuleSoft Connector

May 23, 2022
Stunning aerial shots of the Dolomites in a post-sunset glow

Stunning aerial shots of the Dolomites in a post-sunset glow

May 23, 2022
Klonoa Collection Frame Rate, Resolution And File Size For Switch Revealed

Klonoa Collection Frame Rate, Resolution And File Size For Switch Revealed

May 23, 2022
Advertise with us
Monday, May 23, 2022
Bookmarks
  • Login
  • Register
GetUpdated
  • Home
  • Game Updates
    • Mobile Gaming
    • Playstation News
    • Xbox News
    • Switch News
    • MMORPG
    • Game News
    • IGN
    • Retro Gaming
  • Tech News
    • Apple Updates
    • Jailbreak News
    • Mobile News
  • Software Development
  • Photography
  • Contact
    • Advertise With Us
    • About
No Result
View All Result
GetUpdated
No Result
View All Result
GetUpdated
No Result
View All Result
ADVERTISEMENT

MuleSoft DataWeave: Reading From the File

January 20, 2022
in Software Development
Reading Time:3 mins read
0 0
0
Share on FacebookShare on WhatsAppShare on Twitter


Before we start, let’s go over the following:  

  1.  readurl (): It is dw-core-function and returns parsed content from source at given classpath-based url. readurl(“classpath-based url”,”contentType”).
  2. dynamic selector[()]: Return the value of expression passed in parentheses of dynamic selector [()].

Example of Reading Data From Files

The file in use here is zipcode.json, which has zip codes for different cities in India. It is available at classpath “/src/main/resources/”.

Example 1:

Reading data from a file can be achieved by using readUrl() in DataWeave.

Data in the “zipcode.json” file is as follows:

{

"Indore" : "455001" ,
"Pune" : "411002",
"Bhopal" : "462003",
"Banglore" : "56004"

}

DataWeave Code, to cath parsed value in dwl variable and map it to a field:

%dw 2.0
output application/json
var zipcodes = readUrl("classpath://zipcode.json" , "application/json")
---
{
	"usingVar" : zipcodes,
	"directlyUsingURL" : readUrl("classpath://zipcode.json" , "application/json")
}

Output:

{
    "usingVar": {
        "Indore": "455001",
        "Pune": "411002",
        "Bhopal": "462003",
        "Banglore": "56004"
    },
    "directlyUsingURL": {
        "Indore": "455001",
        "Pune": "411002",
        "Bhopal": "462003",
        "Banglore": "56004"
    }
}

Example 2:

Mapping a field in response from parsed data of the file can be achieved in a single transform node using “readUrl()” and “dynamic selector [()] for single value”.

Data in the “zipcode.json” file: 

{

"Indore" : "455001" ,
"Pune" : "411002",
"Bhopal" : "462003",
"Banglore" : "56004"

}

Input payload:

[
    {
        "city": "Indore"
    },
    {
        "city": "Bhopal"
    }
]

DataWeave code:

%dw 2.0
output application/json
var zipcodes = readUrl("classpath://zipcode.json" , "application/json")
---
payload map ((item, index) -> {
  "City": item.city,
  "Zipcode": zipcodes[item.city]
})

Output:

[
    {
        "City": "Indore",
        "Zipcode": "455001"
    },
    {
        "City": "Bhopal",
        "Zipcode": "462003"
    }
]

Thanks!



Source link

ShareSendTweet
Previous Post

Nintendo Switch System Update 13.2.1 Is Now Live, Here Are The Full Patch Notes

Next Post

The iPhone SE+ 5G will become available in late April or early May, claims analyst

Related Posts

Comparing Distributed Databases – DZone Database

May 23, 2022
0
0
Comparing Distributed Databases – DZone Database
Software Development

The past decade saw the rise of fully distributed databases. Not just local clustering to enable basic load balancing and...

Read more

Data Security Considerations in CDWs

May 23, 2022
0
0
Data Security Considerations in CDWs
Software Development

This is an article from DZone's 2022 Data Pipelines Trend Report.For more: Read the Report Cloud data warehouses (CDWs) are...

Read more
Next Post
The iPhone SE+ 5G will become available in late April or early May, claims analyst

The iPhone SE+ 5G will become available in late April or early May, claims analyst

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

© 2021 GetUpdated – MW.

  • About
  • Advertise
  • Privacy & Policy
  • Terms & Conditions
  • Contact

No Result
View All Result
  • Home
  • Game Updates
    • Mobile Gaming
    • Playstation News
    • Xbox News
    • Switch News
    • MMORPG
    • Game News
    • IGN
    • Retro Gaming
  • Tech News
    • Apple Updates
    • Jailbreak News
    • Mobile News
  • Software Development
  • Photography
  • Contact
    • Advertise With Us
    • About

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?