No matter context pretty attribute is true or not, this method formats the json string you want.

@param pretty pretty or not.
@return formatted json string.
424618
public String toVoJSONString(boolean pretty) {
        if (pretty) {
            return JSON.toJSONStringWithDateFormat(toVoJSONObject(), Constant.DATE_SERIALIZE_FORMAT, SerializerFeature.PrettyFormat);
        } else {
            return JSONObject.toJSONStringWithDateFormat(toVoJSONObject(), Constant.DATE_SERIALIZE_FORMAT);
        }
    }
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)
1284011
public String toJSONString(final boolean compact) {
        final StringBuilder builder = new StringBuilder();
        formatAsJSON(builder, 0, !compact);
        return builder.toString();
    }
1058466
def prettyfy(response, format='json'):
    
    if format == 'json':
        return pretty_json(response.content)
    else:
        return pretty_xml(response.content)
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());
            }
        }
    }
874723
public String toJson(boolean pretty, String... attributeNames) {
        StringBuilder sb = new StringBuilder();
        toJsonP(sb, pretty, "", attributeNames);
        return sb.toString();
    }
153723
public static void serialize(@Nonnull  Writer out, @Nonnull  JsonElement json, boolean pretty) throws IOException {
        BufferedWriter bw = new BufferedWriter(out);
        serialize(bw, json, pretty, 0);
        if(pretty) {
            bw.write('\n');
        }
        bw.flush();
    }
1094840
public static function prettyJSONPrint($json)
    {
        $result = '';
        $level = 0;
        $in_quotes = false;
        $in_escape = false;
        $ends_line_level = null;
        $json_length = strlen($json);

        for ($i = 0; $i < $json_length; $i++) {
            $char = $json[$i];
            $new_line_level = null;
            $post = "";
            if ($ends_line_level !== null) {
                $new_line_level = $ends_line_level;
                $ends_line_level = null;
            }
            if ($in_escape) {
                $in_escape = false;
            } else {
                if ($char === '"') {
                    $in_quotes = !$in_quotes;
                } else {
                    if (!$in_quotes) {
                        switch ($char) {
                            case '}':
                            case ']':
                                $level--;
                                $ends_line_level = null;
                                $new_line_level = $level;
                                break;

                            case '{':
                            case '[':
                                $level++;
                            case ',':
                                $ends_line_level = $level;
                                break;

                            case ':':
                                $post = " ";
                                break;

                            case " ":
                            case "\t":
                            case "\n":
                            case "\r":
                                $char = "";
                                $ends_line_level = $new_line_level;
                                $new_line_level = null;
                                break;
                        }
                    } else {
                        if ($char === '\\') {
                            $in_escape = true;
                        }
                    }
                }
            }
            if ($new_line_level !== null) {
                $result .= "\n" . str_repeat("\t", $new_line_level);
            }
            $result .= $char . $post;
        }

        return $result;
    }
1152988
def pretty_str(self, indent=0):
        
        spaces = ' ' * indent
        pretty = '{}({})' if self.parenthesis else '{}{}'
        name = ('{}.{}'.format(self.field_of.pretty_str(), self.name)
                if self.field_of else self.name)
        return pretty.format(spaces, name)
166751
def json_pretty_dump(obj, filename):
    
    with open(filename, "wt") as fh:
        json.dump(obj, fh, indent=4, sort_keys=4)
240075
def pretty_dumps(data):
    
    try:
        return json.dumps(data, sort_keys=True, indent=4, ensure_ascii=False)
    except:
        return json.dumps(data, sort_keys=True, indent=4, ensure_ascii=True)
995014
public static function jsonEncode($data, $prettyPrint = false)
    {
        $data = static::export($data);

        if (version_compare(PHP_VERSION, '5.4', '>=')) {
            $options = JSON_UNESCAPED_SLASHES | (false !== $prettyPrint ? JSON_PRETTY_PRINT : 0) | JSON_NUMERIC_CHECK;

            return json_encode($data, $options);
        }

        $json = str_replace('\/', '/', json_encode($data));

        return $prettyPrint ? static::pretty_json($json) : $json;
    }
1173863
public function json(bool $beautify = false): string
    {
        if (null === $serialized = $this->serialize()) {
            return '';
        }

        if ($beautify) {
            return json_encode($serialized, JSON_PRETTY_PRINT);
        }

        return json_encode($serialized);
    }
369139
public function asJson($pretty = false, $encode = true)
    {
        $renderer = new HalJsonRenderer();

        return $renderer->render($this, $pretty, $encode);
    }
481727
public String exportToJson(boolean pretty) {
        Map<String, Object> result = new HashMap<String, Object>();
        Map<String, List<Map<String, Object>>> services = new HashMap<String, List<Map<String, Object>>>();

        for (EndpointHealth h : endpoints) {
            String type = serviceTypeFromEnum(h.type());
            if (!services.containsKey(type)) {
                services.put(type, new ArrayList<Map<String, Object>>());
            }
            List<Map<String, Object>> eps = services.get(type);
            eps.add(h.toMap());
        }

        result.put("version", version);
        result.put("services", services);
        result.put("sdk", sdk);
        result.put("id", id);

        try {
            if (pretty) {
                return DefaultObjectMapper.prettyWriter().writeValueAsString(result);
            } else {
                return DefaultObjectMapper.writeValueAsString(result);
            }
        } catch (JsonProcessingException e) {
            throw new IllegalStateException("Could not encode as JSON string.", e);
        }
    }
555866
def as_json(pretty=false)

      pretty ? Rufus::Json.pretty_encode(@h) : Rufus::Json.encode(@h)
    end
392022
public static String pretty(final Source source)
	{
		StreamResult result = new StreamResult(new StringWriter());

		pretty(source, result);

		return result.getWriter().toString();
	}