add prettyjson.dart, pubspec.yaml

This commit is contained in:
2019-11-17 00:10:05 +08:00
parent 1f91e26cd7
commit dbd04e7763
2 changed files with 16 additions and 0 deletions

13
prettyjson.dart Normal file
View File

@@ -0,0 +1,13 @@
import 'dart:convert';
import 'dart:io';
main(List<String> args) async {
if (args.length == 0) {
print('File name is not assigned\nUsage: prettyjson.dart <file.json>');
return;
}
final jsonContent = await new File(args[0]).readAsString();
final jsonDecoded = json.decode(jsonContent);
JsonEncoder encoder = new JsonEncoder.withIndent(' ');
print(encoder.convert(jsonDecoded));
}

3
pubspec.yaml Normal file
View File

@@ -0,0 +1,3 @@
name:
prettyjson.dart