Writes the object out as json.

@param out
output writer
@param json
a {@link JsonElement}
@param pretty
if true, a properly indented version of the json is written
@throws IOException
if there is a problem writing to the stream
193505
public static void serialize(OutputStream out, @Nonnull  JsonElement json, boolean pretty) throws IOException {
        Validate.notNull(out);
        BufferedOutputStream bufferedOut = new BufferedOutputStream(out);
        OutputStreamWriter w = new OutputStreamWriter(bufferedOut, UTF8);
        if(pretty) {
            serialize(w, json, pretty);
        } else {
            json.serialize(w);
            // subtle bug where not flushing this results in empty string when serializing to a ByteArrayOutputStream
            w.flush();
            bufferedOut.flush();
        }
    }
127732
public void write( SystemInputDef systemInput)
    {
    JsonWriterFactory writerFactory = Json.createWriterFactory( MapBuilder.of( PRETTY_PRINTING, true).build());
    JsonWriter jsonWriter = writerFactory.createWriter( getWriter());

    jsonWriter.write( SystemInputJson.toJson( systemInput));
    }
992915
public void serialize(Map<String, T> map, OutputStream os) throws IOException {
        JsonGenerator jsonGenerator = LoganSquare.JSON_FACTORY.createGenerator(os);
        serialize(map, jsonGenerator);
        jsonGenerator.close();
    }
1151751
public void serialize(List<T> list, OutputStream os) throws IOException {
        JsonGenerator jsonGenerator = LoganSquare.JSON_FACTORY.createGenerator(os);
        serialize(list, jsonGenerator);
        jsonGenerator.close();
    }
1228077
void writeObject(java.io.ObjectOutputStream out) throws IOException {
        // when using object serialization, write the json bytes
        byte[] bytes = toString().getBytes(StandardCharsets.UTF_8);
        out.writeInt(bytes.length);
        out.write(bytes);
    }
1254791
public void toJson(Writer writer) throws IOException {
		startArray(writer);

		int size = size();
		for (int i = 0; i < size; i++) {
			put(writer, get(i));
			if (i + 1 < size) {
				addSeparator(writer);
			}
		}

		endArray(writer);
	}
525423
@Override 
  public void write(JsonWriterImpl out, Enum<?> value)
  {
    out.write(value.name());
  }
255572
public void toJson(JsonElement jsonElement, JsonWriter writer) throws JsonIOException {
    boolean oldLenient = writer.isLenient();
    writer.setLenient(true);
    boolean oldHtmlSafe = writer.isHtmlSafe();
    writer.setHtmlSafe(htmlSafe);
    boolean oldSerializeNulls = writer.getSerializeNulls();
    writer.setSerializeNulls(serializeNulls);
    try {
      Streams.write(jsonElement, writer);
    } catch (IOException e) {
      throw new JsonIOException(e);
    } catch (AssertionError e) {
      AssertionError error = new AssertionError("AssertionError (GSON " + GsonBuildConfig.VERSION + "): " + e.getMessage());
      error.initCause(e);
      throw error;
    } finally {
      writer.setLenient(oldLenient);
      writer.setHtmlSafe(oldHtmlSafe);
      writer.setSerializeNulls(oldSerializeNulls);
    }
  }
436518
public <T> void write(final PrintWriter writer, final T object,
			final DataTypeDescriptor<T> descriptor, final boolean indent) {
		try {
			jsonFormat.write(writer, object, descriptor, indent);
		} catch (Exception e) {
			throw propagate(e);
		}
	}
1131018
public void writeTo(Writer writer) throws IOException {
        JsonSerializer.write(Json.jObject("template", asJson()), writer);
        writer.flush();
    }
475556
def dump_json(self, pretty=True):
        
        # Build template
        t = {}
        t['AWSTemplateFormatVersion'] = '2010-09-09'        
        if self.description is not None:
            t['Description'] = self.description
        self.elements.dump_to_template_obj(self, t)

        return _CustomJSONEncoder(indent=2 if pretty else None,
                                  sort_keys=False).encode(t)
1101826
public static <T> void writeJson(T obj, File file) {
    StringWriter writer = new StringWriter();
    try {
      objectMapper.writeValue(writer, obj);
      Files.write(file.toPath(), writer.toString().getBytes());
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
1085620
public static String formatJson(String json) {
    assertInitialization();
    return XLog.sLogConfiguration.jsonFormatter.format(json);
  }
693362
public void write(JsonGenerator jsonGenerator) throws IOException {
    jsonGenerator.writeStartObject();

    int totalSessionsToCtx = 0, totalDeletedSessions = 0;
    for (int i = 0; i < numNotifierThreads; i++) {
      totalSessionsToCtx += notifierThreads[i].sessionsToCtx.size();
      totalDeletedSessions += notifierThreads[i].deletedSessions.size();
    }

    jsonGenerator.writeNumberField("totalSessionsToCtx",
                                    totalSessionsToCtx);

    jsonGenerator.writeFieldName("sessionsToCtx");
    jsonGenerator.writeStartObject();
    for (int i = 0; i < numNotifierThreads; i++) {
      for (ConcurrentMap.Entry<String, SessionNotificationCtx> entry :
        notifierThreads[i].sessionsToCtx.entrySet()) {
        jsonGenerator.writeFieldName(entry.getKey());
        entry.getValue().write(jsonGenerator);
      }
    }
    jsonGenerator.writeEndObject();

    jsonGenerator.writeNumberField("totalDeletedSessions",
                                    totalDeletedSessions);

    jsonGenerator.writeFieldName("deletedSessions");
    jsonGenerator.writeStartArray();
    for (int i = 0; i < numNotifierThreads; i++) {
      for (String deletedSessionHandle :
            notifierThreads[i].deletedSessions.keySet()) {
        jsonGenerator.writeString(deletedSessionHandle);
      }
    }
    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
  }
756929
public void writeJSON(JSONValue jc, JSONWriter jb, boolean writeClass)
            throws IOException {
        jb.arrayBegin();
        for (Object item : mArray) {
            if (item == null)
                jb.valueNull();
            else
                jc.writeValue(item, jb, writeClass);
        }
        jb.arrayEnd();
    }
1191452
private void pretifyJson(String pathToJson) throws ReportException {
        final String outputPath = pathToJson + ".pretty";
        final File in = new File(pathToJson);
        final File out = new File(outputPath);
        try (JsonReader reader = new JsonReader(new InputStreamReader(new FileInputStream(in), StandardCharsets.UTF_8));
                JsonWriter writer = new JsonWriter(new OutputStreamWriter(new FileOutputStream(out), StandardCharsets.UTF_8))) {
            prettyPrint(reader, writer);
        } catch (IOException ex) {
            LOGGER.debug("Malformed JSON?", ex);
            throw new ReportException("Unable to generate json report", ex);
        }
        if (out.isFile() && in.isFile() && in.delete()) {
            try {
                org.apache.commons.io.FileUtils.moveFile(out, in);
            } catch (IOException ex) {
                LOGGER.error("Unable to generate pretty report, caused by: {}", ex.getMessage());
            }
        }
    }
1329989
public void dumpJson(final PrintWriter out) {
        out.append("{");
        visitVariables(new Visitor() {
            int count = 0;

            public void visit(Variable var) {
                if (count++ > 0) { out.append(", "); }
                out.append(var.getName()).append("='").append(String.valueOf(var.getValue())).append("'");
            }
        });
        out.append("}");
    }