0

I need to generate an xml from a Json object and I am able to do that successfully. However some of the keys in that json object look like this,

{  
   "UNIX":"/BIN/BASH",
   "STATUS operation='remove'":"EXPIRED",
   "USERS operation='remove'":"[MATT]",
   "DATE operation='ADD'":"20-MAY-17",
   "FIRST_NAME":"ABC", 
}

So, when I am converting this Json to an xml, I am getting the xml as this,

<?xml version="1.0" encoding="UTF-8"?>
  <user userid="abcid">
  <UNIX>/BIN/BASH</UNIX>
  <STATUS operation='remove'>EXPIRED</STATUS operation='remove'>
  <USERS operation='remove'>[ILMT0004]</USERS operation='remove'>
  <DATE operation='ADD'>20-APR-17</DATE operation='ADD'>
  <FIRST_NAME>MATT</FIRST_NAME>
  </user>

As you can see, the key in the json is getting generated as the start and the end tags in the xml, I want that operation='remove' string only in the start tag.I don't need it in the end tag of the xml. The end tag should simply be like </DATE>.

How I can get rid of any characters that are present after a space in the end tags using java?

James Z
  • 12,209
  • 10
  • 24
  • 44
user3546785
  • 157
  • 1
  • 7
  • 16

1 Answers1

0

Looks like your json is not accurate/valid (I believe it should be key value pairs, even the tree can be deeper, and the key will always be without space) to check its validity you can use any online website e.g. https://jsonformatter.org/

Your Json elements need be properly defined e.g. "FIRST_NAME":"ABC has key without space.

reference on how to convert JSON to XML - Converting JSON to XML in Java

mAc
  • 61
  • 4