1

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

Simon Karlsson
  • 4,090
  • 22
  • 39
user3165854
  • 1,505
  • 8
  • 48
  • 100

2 Answers2

2

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");
sulthony h
  • 1,279
  • 1
  • 8
  • 9
  • Please answer this question : https://stackoverflow.com/questions/61095074/how-to-convert-managedcursorstreamprovider-to-json-object-in-mule-4 – HMT Apr 08 '20 at 08:49
0

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());
Simon Karlsson
  • 4,090
  • 22
  • 39
sachin k
  • 236
  • 2
  • 10