diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2017-12-13 12:52:15 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2017-12-13 12:52:15 +0530 |
commit | 352ae4ea02fd0e30e20b49b320bc601f45fd7560 (patch) | |
tree | 8971a2daf7bc3de0e70707ea9a912b2c176b93d2 /framework/src/main/java | |
parent | 8356f97171f8cec8ff07a7d39f5fef5c49e85063 (diff) |
Add json print format
Issue-ID: CLI-66
Change-Id: Ic032912de0b302352f5c8ed94749ddd012f55af6
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/main/java')
-rw-r--r-- | framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java index 3946c5da..389aee36 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java +++ b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java @@ -31,6 +31,9 @@ import org.apache.commons.csv.CSVPrinter; import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed; import org.onap.cli.fw.output.OnapCommandPrintDirection; +import net.minidev.json.JSONArray; +import net.minidev.json.JSONObject; + /** * Oclip Command Table print. * @@ -241,8 +244,20 @@ public class OnapCommandPrint { } public String printJson() { - // (mrkanag) print in json - return null; + List<List<Object>> rows = this.formRows(false); + + JSONArray array = new JSONArray(); + + //skip first row title + for (int i=1; i<rows.size(); i++) { + JSONObject rowO = new JSONObject(); + for (Object col: rows.get(0)) { + rowO.put(col.toString(), rows.get(i).toString()); + } + array.add(rowO); + } + + return array.toJSONString(); } public String printYaml() { |