Java Utililty Methods Map to Json

List of utility methods to do Map to Json

Description

The list of methods to do Map to Json are organized into topic(s).

Method

StringmapToJson(Map map)
map To Json
final StringBuilder sb = new StringBuilder("{");
Iterator<Map.Entry<String, Object>> itr = map.entrySet().iterator();
while (itr.hasNext()) {
    Map.Entry<String, Object> e = itr.next();
    sb.append('"').append(e.getKey()).append("\":\"").append(e.getValue().toString()).append('"');
    if (itr.hasNext())
        sb.append(", ");
return sb.append('}').toString();
StringmapToJson(Map map, boolean pretty, String indent)
map To Json
StringBuilder builder = new StringBuilder(1024);
builder.append(pretty ? indent + "{\n" : "{");
int count = 0;
for (Entry<String, Object> entry : map.entrySet()) {
    final String key = entry.getKey();
    final Object val = entry.getValue();
    if (count > 0) {
        builder.append(pretty ? ",\n" : ",");
...
StringmapToJson(Map parameters)
map To Json
return null;
StringmapToJson(Map map)
map To Json
StringBuffer json = new StringBuffer("{");
int index = 0;
for (String key : map.keySet()) {
    if (index > 0) {
        json.append(",");
    json.append("'" + key + "':'" + map.get(key) + "'");
    index++;
...
StringtoJson(Map map)
join map
if (map == null || map.size() == 0) {
    return null;
StringBuilder paras = new StringBuilder();
paras.append("{");
Iterator<Map.Entry<String, String>> ite = map.entrySet().iterator();
while (ite.hasNext()) {
    Map.Entry<String, String> entry = (Map.Entry<String, String>) ite.next();
...
StringtoJSON(Map map)
to JSON
if (map == null)
    return null;
else if (map.size() == 0)
    return "{}";
StringBuilder jsonBuilder = new StringBuilder(map.containsKey("") ? map.get("") : "");
jsonBuilder.append(JSON_OBJECT_START);
for (Map.Entry<String, String> entry : map.entrySet()) {
    String key = entry.getKey();
...
StringtoJSON(Map map)
to JSON
StringBuilder builder = new StringBuilder();
builder.append('{');
boolean first = true;
for (Map.Entry<String, String> entry : map.entrySet()) {
    if (first)
        first = false;
    else
        builder.append(',');
...
StringtoJSON(Map map)
Builds a JSON string form the given map
StringBuffer sb = new StringBuffer("{");
for (String key : map.keySet()) {
    String optionValue = map.get(key);
    if (sb.length() > 1) {
        sb.append(",");
    sb.append("\"" + key + "\"");
    sb.append(":");
...
StringtoJSONString(Map map, int indentLevel)
Convert a map to JSON text.
int subIndentLevel = indentLevel + 1;
if (map == null)
    return getIndent(indentLevel) + "null";
StringBuffer sb = new StringBuffer();
boolean first = true;
Iterator<T> iter = map.keySet().iterator();
sb.append('{');
sb.append("\n");
...