diff -ur v5/ezyaml.py v6/ezyaml.py --- v5/ezyaml.py 2018-08-31 05:15:00.000000000 +0900 +++ v6/ezyaml.py 2018-08-31 22:53:33.000000000 +0900 @@ -201,6 +201,17 @@ lines.append(s) return '\n'.join(lines) +def need_quote(s): + kwd = [ '', 'True', 'true', 'TRUE', 'False', 'false', 'FALSE', 'ON', 'On', 'on', 'OFF', 'Off', 'off' ] + if s in kwd: + return True + + hts = [ ('[', ']'), ('{', '}') ] + if ( s[:1], s[-1:] ) in hts: + return True + + return False + def dump_value(obj): if type(obj) == str: s = obj @@ -208,7 +219,7 @@ if q2 and q1: s = s.replace("'", "\\'") q1 = False - if q2 or q1 or cl or get_value(s) != obj or s == '': + if q2 or q1 or cl or get_value(s) != obj or need_quote(s): qt = '"' if q1 else "'" s = qt + s + qt return s @@ -219,6 +230,9 @@ if type(obj) == dict: return '{}' + if obj == None: + return 'null' + return '{}'.format(obj) def dump_other(obj, idt):