0

I am having a converting that in to Json with following code

    JSONObject jsonformatted = (JSONObject)JSONSerializer.toJSON(map);
    FileWriter writer = new FileWriter("myfile.json");

It is working fine and out put is following

        [ {"date":"July 4th", "event":"Independence Day"} ]

But I want the following format with a variable assign get value in Json

           jsonstr = [ {"date":"July 4th", "event":"Independence Day"} ];

How can i add a variable to that

Michael
  • 3,982
  • 4
  • 30
  • 46
Amit
  • 196
  • 4
  • 16

1 Answers1

0

You can add a new data using put method in JSONObject

JSONObject jsonformatted = (JSONObject)JSONSerializer.toJSON(map);

jsonformatted .put("assign ", "some value")

Edit

OP wants to replace ':' with '=' Well you should not do it , because its the JSON standard. Attributes and values are assigned using : and not by = Check this link for more info JSON wiki

Sudhakar
  • 4,823
  • 2
  • 35
  • 42
  • it is giving as "assign" : [ {"date":"July 4th", "event":"Independence Day"} ]; but i want = sign place of : sign – Amit Feb 27 '13 at 09:22