dregenor / jsonMapper

simple json mapper
MIT License
31 stars 8 forks source link

Computing residue? #13

Open devetops opened 7 years ago

devetops commented 7 years ago

Is there a way to use json-mapper to determine the unmapped residue? That is, if I create a converter and I map a bunch of fields from one JSON format into a target format, is there a way to get a list of fields that weren't converted (i.e. dropped) from the input?

dregenor commented 7 years ago

Hi. Thank you for question.

Currently out of the box, it is impossible.

But if you want get "unmapped" fields (skipped in output) you can modify the code in function "applySchema", and instead if ( typeof val !== "undefined" ){ output[par] = val; } use something like if ( typeof val !== "undefined" ){ output[par] = val; } else {output[par]='_unmapped_'} or put unmapped fields in another container.

Another question how to determine what fields from input were skipped. At first sight need use some mechanism to mark field as "touched", and show "untouched fields" after applying schema, but I must do some research, before present some decision.

Anyway, it good feature request, i think i will implement something like "debug" mode for this case, but i don't know when. May be on the end of next week(or two).

mugwump commented 6 years ago

...and speaking of residue: Is it possible to return the original json and have only the converted values changed? Now everything that is not converted is thrown away...