@@ -196,14 +196,14 @@ def LoadJson(contents: str) -> "Node":
196
196
""" Import a new Node from a JSON string """
197
197
return jsonod .generate_node (contents )
198
198
199
- def DumpFile (self , filepath : TPath , filetype : str | None = "json " , ** kwargs ):
199
+ def DumpFile (self , filepath : TPath , filetype : str | None = "jsonc " , ** kwargs ):
200
200
""" Save node into file """
201
201
202
202
# Attempt to determine the filetype from the filepath
203
203
if not filetype :
204
204
filetype = Path (filepath ).suffix [1 :]
205
205
if not filetype :
206
- filetype = "json "
206
+ filetype = "jsonc "
207
207
208
208
if filetype == 'od' :
209
209
log .debug ("Writing XML OD '%s'" , filepath )
@@ -219,9 +219,11 @@ def DumpFile(self, filepath: TPath, filetype: str|None = "json", **kwargs):
219
219
f .write (content )
220
220
return
221
221
222
- if filetype == 'json' :
222
+ if filetype in ( 'json' , 'jsonc' ) :
223
223
log .debug ("Writing JSON OD '%s'" , filepath )
224
- jdata = self .DumpJson (** kwargs )
224
+ kw = kwargs .copy ()
225
+ kw ['jsonc' ] = filetype == 'jsonc'
226
+ jdata = self .DumpJson (** kw )
225
227
with open (filepath , "w" , encoding = "utf-8" ) as f :
226
228
f .write (jdata )
227
229
return
@@ -234,10 +236,10 @@ def DumpFile(self, filepath: TPath, filetype: str|None = "json", **kwargs):
234
236
235
237
raise ValueError ("Unknown file suffix, unable to write file" )
236
238
237
- def DumpJson (self , compact = False , sort = False , internal = False , validate = True ) -> str :
239
+ def DumpJson (self , compact = False , sort = False , internal = False , validate = True , jsonc = True ) -> str :
238
240
""" Dump the node into a JSON string """
239
241
return jsonod .generate_jsonc (
240
- self , compact = compact , sort = sort , internal = internal , validate = validate
242
+ self , compact = compact , sort = sort , internal = internal , validate = validate , jsonc = jsonc
241
243
)
242
244
243
245
def asdict (self ) -> dict [str , Any ]:
0 commit comments