Lucky Lucky - 3 months ago 9x
JSON Question

How to get single quoted string array in JSON output?

I have the model class to return a JSON output with two array values, one array containing int values and another with single quotes words.

class RGraph{
int[] data;
String[] labels;

// getters and setters

When I return the RGraph class as JSON response from Spring controller with
, I get the following result as json o/p,


But what my expected output is,

labels: ['Gary','Olga','Lewis','Rachel','Nathan','Matt','Kevin','Indigo','Lou','Pete']

In the above JSON response, I have two questions

  • How to remove the double quotes for keys? and

  • How to replace double quotes with single quotes in values?

I need this format because RGraph Chart library expects the values with single quotes for its labels and tooltips.


If you're referring to my RGraph charting library - single quotes and double quotes around strings are usually interchangeable, and keys for objects don't have to be quoted (unless they contain certain characters). Eg

'colors': ["red",'yellow',"#0f0",'blue'],
tooltips: ["a","b","c","d"]