1

In my Java program, I have pipeline separated string "value1|value2|value3|value4". I would like to convert that string to a JSON object in java like the following:

{ “ payload” : { "field1": value1, "field2": value2, "field3": value3, "field4": value4 } }

And I would like to read field1, field2, field3, field4 from a configuration file. Is it possible to do that transformation with Smooks or with any other library ?

Casper
  • 107
  • 2
  • 12
  • While it is possible, why on earth the extra "rediction"? Why do you need the "payload" at all here? – fge Nov 08 '15 at 18:15
  • It is not clear what you are talking about when you say "JSON object". JSON is not an object class, it is a data _serialization format_. Do you mean: You want to print your data structure (the nested hashtables) using JSON? – hagello Nov 08 '15 at 19:33
  • @hagello, in my java program, I want to convert the string "value1|value2|value3|value4" to json string "{ “ payload” : { "field1": value1, "field2": value2, "field3": value3, "field4": value4 } }". I want to read the field value mappings from a configuration file and I want to use a third party library to do that transformation. – Casper Nov 08 '15 at 22:33
  • @fge, let's forget about the "payload" for the moment. I mean, let's say that I don't need the "payload" here. How can I do the transformation which I'm asking in my question ? – Casper Nov 08 '15 at 22:34
  • @hagello, are there still unclear points in my question ? – Casper Nov 09 '15 at 05:43
  • Could you edit your question accordingly? – hagello Nov 09 '15 at 07:36
  • Why do you need a third party library. With String.split and System.out.printf You can do it in two lines (assuming you already read the field values from the config file.) – Jerry Jeremiah Aug 13 '18 at 23:21
  • If you really want a third party library you are probably looking for a template engine like Apache Velocity – Jerry Jeremiah Aug 13 '18 at 23:24

0 Answers0