Format object into json.
@param object of data to be formatted
@return string in json format
510908
public static function objectToJson($object = false, $pretty = false) {

        if ($object && Validate::isObject($object)) {

            $array = self::objectToArray($object);
            return self::arrayToJson($array, $pretty);
        }

        return false;
    }
416247
public static String format(final Object object, final String pattern) {
		if (object instanceof Date) {
			return JKFormatUtil.formatDate((Date) object, pattern);
		}
		if (object instanceof Time) {
			return JKFormatUtil.formatTime((Time) object, pattern);
		}
		if (object instanceof Timestamp) {
			return JKFormatUtil.formatTimeStamp((Timestamp) object, pattern);
		}
		if (object instanceof java.util.Date) {
			return JKFormatUtil.formatDate((java.util.Date) object, pattern);
		}
		if (object instanceof Double) {
			return JKFormatUtil.formatDouble((Double) object, pattern);
		}
		if (object != null) {
			return object.toString();
		}
		return null;
	}
823819
protected Object formatObject(Object object)
    {
        Object formattedObject=object;
        if(object==null)
        {
            formattedObject="";
        }
        else if(object instanceof String)
        {
            //get string
            String string=(String)object;
            
            //remove characters
            string=string.replaceAll("\n","");
            string=string.replaceAll("\r","");
            string=string.replaceAll("\t","");
            string=string.replaceAll("\f","");
            string=string.replaceAll("\b","");
            string=string.replaceAll("'","");
            string=string.replaceAll("\"","");
            
            //get reference
            formattedObject=string;
        }
        else if(object instanceof File)
        {
            //get file
            File file=(File)object;

            String filePath=null;
            try
            {
                filePath=file.getCanonicalPath();
            }
            catch(IOException exception)
            {
                throw new FaxException("Unable to get file path.",exception);
            }
            filePath=filePath.replaceAll("\\\\","\\\\\\\\");
            
            //get reference
            formattedObject=filePath;
        }
        
        return formattedObject;
    }
441259
public ObjectNode toJsonNode(ObjectNode object) {
        object.put("type", "rich");
        if (title != null && !title.equals("")) {
            object.put("title", title);
        }
        if (description != null && !description.equals("")) {
            object.put("description", description);
        }
        if (url != null && !url.equals("")) {
            object.put("url", url);
        }
        if (color != null) {
            object.put("color", color.getRGB() & 0xFFFFFF);
        }
        if (timestamp != null) {
            object.put("timestamp", DateTimeFormatter.ISO_INSTANT.format(timestamp));
        }
        if ((footerText != null && !footerText.equals("")) || (footerIconUrl != null && !footerIconUrl.equals(""))) {
            ObjectNode footer = object.putObject("footer");
            if (footerText != null && !footerText.equals("")) {
                footer.put("text", footerText);
            }
            if (footerIconUrl != null && !footerIconUrl.equals("")) {
                footer.put("icon_url", footerIconUrl);
            }
            if (footerIconContainer != null) {
                footer.put("icon_url", "attachment://" + footerIconContainer.getFileTypeOrName());
            }
        }
        if (imageUrl != null && !imageUrl.equals("")) {
            object.putObject("image").put("url", imageUrl);
        }
        if (imageContainer != null) {
            object.putObject("image").put("url", "attachment://" + imageContainer.getFileTypeOrName());
        }
        if (authorName != null && !authorName.equals("")) {
            ObjectNode author = object.putObject("author");
            author.put("name", authorName);
            if (authorUrl != null && !authorUrl.equals("")) {
                author.put("url", authorUrl);
            }
            if (authorIconUrl != null && !authorIconUrl.equals("")) {
                author.put("icon_url", authorIconUrl);
            }
            if (authorIconContainer != null) {
                author.put("icon_url", "attachment://" + authorIconContainer.getFileTypeOrName());
            }
        }
        if (thumbnailUrl != null && !thumbnailUrl.equals("")) {
            object.putObject("thumbnail").put("url", thumbnailUrl);
        }
        if (thumbnailContainer != null) {
            object.putObject("thumbnail").put("url", "attachment://" + thumbnailContainer.getFileTypeOrName());
        }
        if (fields.size() > 0) {
            ArrayNode jsonFields = object.putArray("fields");
            for (EmbedField field : fields) {
                ObjectNode jsonField = jsonFields.addObject();
                jsonField.put("name", field.getName());
                jsonField.put("value", field.getValue());
                jsonField.put("inline", field.isInline());
            }
        }
        return object;
    }
1299817
public String serialize(Object object) throws ConverterException {
	deep = 0;
	StringBuilder sb = new StringBuilder();
	_serialize(object, sb, new HashSet<Object>());
	return sb.toString();
    }
618560
function(object) {
    if (!this.stringify) return JSON.stringify(object);

    return this.stringify(object, function(key, value) {
      return (this[key] instanceof Array) ? this[key] : value;
    });
  }
290512
public static String format(Object data) {

        if (data == null) {
            return null;
        }
        Class<?> clazz = data.getClass();
        if (clazz.equals(Date.class)) {
            return format(((Date)data).getTime());
        }
        return data.toString();
    }
351260
public static String toJson(Object obj) {
		try {
			return objectMapper.writeValueAsString(obj);
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		}
	}
268621
function format (args) {
  return args.map((v) => {
    const type = Object.prototype.toString.call(v)
    if (type.toLowerCase() === '[object object]') {
      v = JSON.stringify(v)
    }
    else {
      v = String(v)
    }
    return v
  })
}
1042068
public static String renderJson(Object o) {

        Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
                .create();
        return gson.toJson(o);
    }
449389
String format(final Object obj) {
		if (obj instanceof Date) {
			return format((Date) obj);
		} else if (obj instanceof Calendar) {
			return format((Calendar) obj);
		} else if (obj instanceof Long) {
			return format(((Long) obj).longValue());
		} else {
			throw new IllegalArgumentException("Unknown class: " + (obj == null ? "<null>" : obj.getClass().getName()));
		}
	}
63887
private static String jsonEncode(Object object) throws IOException {
      
      ObjectMapper mapper = new ObjectMapper();
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      try {
         mapper.writeValue(outputStream, object);
         return new String(outputStream.toByteArray());
      } catch (JsonGenerationException e) {
         logger.severe("unable encode");
         throw new IOException(e);
      } catch (JsonMappingException e) {
         logger.severe("unable encode");
         throw new IOException(e.getMessage());
      }
      
   }
1022659
@Override
	public String toJson(Object obj) {
		try {
			String json;
			if (obj == null) {
				json = null;
			}
			else {
				json = mapper.writeValueAsString(obj);
			}
			return json;
		}
		catch (Exception e) {
			throw new JsonException(e.getMessage(), e);
		}
	}
467682
function formatObject(o) {
		var s = String(o);
		if(s === '[object Object]' && typeof JSON !== 'undefined') {
			s = tryStringify(o, s);
		}
		return s;
	}
109755
public static String toJson(Object obj) {
        StringWriter sw = new StringWriter();
        ObjectMapper mapper = getDefaultObjectMapper();
        try {
            JsonGenerator jg = mapper.getFactory().createGenerator(sw);
            mapper.writeValue(jg, obj);
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (JsonGenerationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sw.toString();
    }
505457
public String objectToString(T object) {
		StringBuilder sb = new StringBuilder(64);
		sb.append(object.getClass().getSimpleName());
		for (FieldType fieldType : fieldTypes) {
			sb.append(' ').append(fieldType.getColumnName()).append('=');
			try {
				sb.append(fieldType.extractJavaFieldValue(object));
			} catch (Exception e) {
				throw new IllegalStateException("Could not generate toString of field " + fieldType, e);
			}
		}
		return sb.toString();
	}
147455
public static byte[] serialize(Object object) {
    	try {
			return serializer.serialize(object);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
    }