Lucky Lucky - 1 year ago 61
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.

Answer Source

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"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download