@@ -303,18 +303,18 @@ function buildObject (schema, code, name, externalSchema, fullSchema) {
303303 var laterCode = ''
304304
305305 Object . keys ( schema . properties || { } ) . forEach ( ( key , i , a ) => {
306- // Using obj. key !== undefined instead of obj.hasOwnProperty(prop) for perf reasons,
306+ // Using obj[' key'] !== undefined instead of obj.hasOwnProperty(prop) for perf reasons,
307307 // see https://github.com/mcollina/fast-json-stringify/pull/3 for discussion.
308308 code += `
309- if (obj. ${ key } !== undefined) {
309+ if (obj[' ${ key } '] !== undefined) {
310310 json += '${ $asString ( key ) } :'
311311 `
312312
313313 if ( schema . properties [ key ] [ '$ref' ] ) {
314314 schema . properties [ key ] = refFinder ( schema . properties [ key ] [ '$ref' ] , fullSchema , externalSchema )
315315 }
316316
317- const result = nested ( laterCode , name , '.' + key , schema . properties [ key ] , externalSchema , fullSchema )
317+ const result = nested ( laterCode , name , key , schema . properties [ key ] , externalSchema , fullSchema )
318318
319319 code += result . code
320320 laterCode = result . laterCode
@@ -392,6 +392,7 @@ function nested (laterCode, name, key, schema, externalSchema, fullSchema) {
392392 var code = ''
393393 var funcName
394394 const type = schema . type
395+ const accessor = key . indexOf ( '[' ) === 0 ? key : `['${ key } ']`
395396 switch ( type ) {
396397 case 'null' :
397398 code += `
@@ -400,36 +401,36 @@ function nested (laterCode, name, key, schema, externalSchema, fullSchema) {
400401 break
401402 case 'string' :
402403 code += `
403- json += $asString(obj${ key } )
404+ json += $asString(obj${ accessor } )
404405 `
405406 break
406407 case 'integer' :
407408 code += `
408- json += $asInteger(obj${ key } )
409+ json += $asInteger(obj${ accessor } )
409410 `
410411 break
411412 case 'number' :
412413 code += `
413- json += $asNumber(obj${ key } )
414+ json += $asNumber(obj${ accessor } )
414415 `
415416 break
416417 case 'boolean' :
417418 code += `
418- json += $asBoolean(obj${ key } )
419+ json += $asBoolean(obj${ accessor } )
419420 `
420421 break
421422 case 'object' :
422423 funcName = ( name + key ) . replace ( / [ - . \[ \] ] / g, '' ) // eslint-disable-line
423424 laterCode = buildObject ( schema , laterCode , funcName , externalSchema , fullSchema )
424425 code += `
425- json += ${ funcName } (obj${ key } )
426+ json += ${ funcName } (obj${ accessor } )
426427 `
427428 break
428429 case 'array' :
429430 funcName = ( name + key ) . replace ( / [ - . \[ \] ] / g, '' ) // eslint-disable-line
430431 laterCode = buildArray ( schema , laterCode , funcName , externalSchema , fullSchema )
431432 code += `
432- json += ${ funcName } (obj${ key } )
433+ json += ${ funcName } (obj${ accessor } )
433434 `
434435 break
435436 default :
0 commit comments