Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change /bd save to save JSON pretty-printed #2

Open
ChiriVulpes opened this issue Feb 15, 2018 · 1 comment
Open

Change /bd save to save JSON pretty-printed #2

ChiriVulpes opened this issue Feb 15, 2018 · 1 comment

Comments

@ChiriVulpes
Copy link

https://github.com/TheAwesomeGem/BlockDropsTweaker/blob/master/src/main/java/net/theawesomegem/blockdropstweaker/common/blockconfig/ConfigurationHandler.java#L156-L169

This is the way I write JsonObjects to strings in my mod:

private static String getJsonString (final JsonObject json, final String indent) {
	try {
		final StringWriter stringWriter = new StringWriter();
		final JsonWriter jsonWriter = new JsonWriter(stringWriter);
		jsonWriter.setLenient(true);
		jsonWriter.setIndent(indent == null ? "" : indent);
		Streams.write(json, jsonWriter);
		return stringWriter.toString();

	} catch (final IOException e) {
		return null;
	}
}

And then you just provide the method with the string it should indent with. Passing null or an empty string does minified JSON (like it is currently).

@darchitectlp
Copy link

In the meantime, if you use Sublime Text, install the "JSON Reindent" package. Fix you right up. But I agree, it'd be nice to have this as the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants