user3165854
user3165854

Reputation: 1655

Get JSON value from JSON which is type string in Mule data mapper

I am using Mule 3.6.1 and in datamapper I have a JSON object which is a string datatype and I need to get the value of a field from the JSON object.

How can I get this value from the JSON object while the object is of type String?

I cannot use the JSON transformer for this.

Thanks for any help

Upvotes: 1

Views: 124

Answers (2)

sulthony h
sulthony h

Reputation: 1277

To convert a String of JSON and get one of its field value inside DataMapper, then you can utilize code like this (in DataMapper Script area):

jsonObject = new org.json.JSONObject(input.jsonstring);
output.jsonValue = jsonObject.getString("jsonfield");

Upvotes: 2

sachin k
sachin k

Reputation: 246

In order to convert JSON element to a series of objects. Google GSon library is very helpful.

Example:

import com.google.gson.Gson;

Gson gson = new Gson();
Student studentTest = gson.fromJson(data, Student.class);

System.out.println("Amount: " + studentTest .getStudentName());

Upvotes: 0

Related Questions