Skip to content

SeparatorStyle option to avoid flattening arrays of primitive types#13

Open
jdub wants to merge 2 commits intojeremywohl:masterfrom
jdub:primitive-arrays
Open

SeparatorStyle option to avoid flattening arrays of primitive types#13
jdub wants to merge 2 commits intojeremywohl:masterfrom
jdub:primitive-arrays

Conversation

@jdub
Copy link

@jdub jdub commented Jul 20, 2020

Normally,

{"a": [1, 2, 3], "m": {"key": "value"}}

would be flattened to,

{"a.0": 1, "a.1": 2, "a.2": 3, "m.key": "value"}

But in many cases, it's preferable to leave arrays of primitive types (such as numbers and strings) as they are, e.g.

("a": [1, 2, 3], "m.key": "value"}

The new SeparatorStyle.DoNotFlattenPrimitiveArrays option is off by default so the default behaviour doesn't change. Sadly, that's also why it has to be an ugly negative option.

jdub added 2 commits July 9, 2020 21:30
Normally,

  {"a": [1, 2, 3], "m": {"key": "value"}}

would be flattened to,

  {"a.0": 1, "a.1": 2, "a.2": 3, "m.key": "value"}

But in many cases, it's preferable to leave arrays of primitive types (such
as numbers and strings) as they are, e.g.

  ("a": [1, 2, 3], "m.key": "value"}

The new SeparatorStyle.DoNotFlattenPrimitiveArrays option is off by default
so the default behaviour doesn't change. Sadly, that's also why it has to be
an ugly negative option.
@jeremywohl
Copy link
Owner

Hi Jeff. Thanks for your patch. Can you explain the use case for this?

Re the patch, I assume you were trying to avoid a breaking change with this option in SeparatorStyle, where it really belongs as a call param?

@jdub
Copy link
Author

jdub commented Aug 10, 2020

Yeah – I have a destination that can't really handle structure (objects), but is totally fine with arrays of primitives.

(I'd even argue that this is a nicer default, because flattened arrays look uuuuugly. But others might require flatness more than they desire beauty. 😄)

@AtakanColak
Copy link

AtakanColak commented Jan 15, 2021

A seperator style with "don't flatten arrays" option would be useful (in my case I also need to include bool and nil values to use this PR). I'm also in need of such a functionality. I can add a method on the map produced but it won't be efficient in performance.

Please do take a look at my fork with SkipArrays

@jeremywohl
Copy link
Owner

@AtakanColak Say more about bool and nil -- I don't see that in your patch.

@AtakanColak
Copy link

@jeremywohl It has been almost a year so I can't remember. Might even delete my fork sometime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants