From dbd04e77632aa2db9c399f8e12e4874c06ea1918 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 17 Nov 2019 00:10:05 +0800 Subject: [PATCH] add prettyjson.dart, pubspec.yaml --- prettyjson.dart | 13 +++++++++++++ pubspec.yaml | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 prettyjson.dart create mode 100644 pubspec.yaml diff --git a/prettyjson.dart b/prettyjson.dart new file mode 100644 index 0000000..b063714 --- /dev/null +++ b/prettyjson.dart @@ -0,0 +1,13 @@ +import 'dart:convert'; +import 'dart:io'; + +main(List args) async { + if (args.length == 0) { + print('File name is not assigned\nUsage: prettyjson.dart '); + return; + } + final jsonContent = await new File(args[0]).readAsString(); + final jsonDecoded = json.decode(jsonContent); + JsonEncoder encoder = new JsonEncoder.withIndent(' '); + print(encoder.convert(jsonDecoded)); +} diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..23fde30 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,3 @@ +name: + prettyjson.dart +