manual: CI check with nitunit
[nit.git] / lib / msgpack / msgpack_to_json.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Convert MessagePack format to JSON
16 module msgpack_to_json
17
18 import msgpack::read
19 import json
20
21 if args.has("-h") then
22 print "Usage: nit msgpack::msgpack_to_json [source_file.msgpack]"
23 print "Convert MessagePack format to JSON. Read from stdin if no source_file is given."
24 exit 0
25 end
26
27 var reader = if args.length >= 1 then
28 new FileReader.open(args.first)
29 else stdin
30
31 while reader.last_error == null and not reader.eof do
32 var deserialized = reader.read_msgpack
33
34 if deserialized != null then
35 print deserialized.serialize_to_json(plain=true, pretty=true)
36 else
37 print "null"
38 end
39 end