Thank you so much for all of your responses. I am not aware of the procedure for suggesting ideas but building a PyPI package with documentation and then sharing here seems like a good way to build this out (which I will get started on). Also, scalpl looks really cool, although I am not sure it does any mapping or support non-standard data types (will check it out more).

Also, if this wasn't clear before, my interpretation of the JSON library's dump function was that it was a very specific implementation of an otherwise generic nested iteration technique for mapping nested data structures from a domain to the JSON domain, where the mapping may not be invertible. Once generically implemented, JSON dumps would use the nested iteration functionality to map any nested data structure onto the JSON domain, the string representation of the resulting structure would be a valid JSON string. So, this should be a generalization of an existing method to map any nested data structure between different domains, where the mapping could be altering dictionary keys, the type of a value or object, or traversing other nested data types.

On Wed, Jul 21, 2021 at 12:38 PM Christopher Barker <pythonchb@gmail.com> wrote:
I would add that this seems to me like something  you need.

So be all means write it, document it, maybe publish it on PyPi, and then, if it does seem to be generally useful, propose it for the stdlib. 

In fact, if something like this were to be included in the stdlib, we’d probably want a back-port on PyPi anyway.

Meanwhile, a few thoughts:

1) it likely makes sense to support Mappings and Iterables, rather than specific types. Though special casing strings, as they are usually treated at atomic in this context.

2) you talk about a use case of flattening to be subset checking. This strikes me as a special case that will require a custom class ( or functions) In particular, how do you deal with dict ordering?

3) is there really no existing JSON-LD lib for Python? Or not a good one? If so, then that’s clearly a package for PyPi, and maybe you’ll discover whether this flattening function is generally useful after it’s been battle tested.

I for one, am interested. I’ve got a system built of nested Dataclasses that serialize to/from JSON compatible nested dicts and lists.

This traversing/flattening functionality could be quite useful.

-CHB

On Wed, Jul 21, 2021 at 8:48 AM Paul Moore <p.f.moore@gmail.com> wrote:
Maybe your examples aren't making it clear what you're suggesting,
then. I'm in agreement with Chris, your "nested iteration tool" sounds
like something that would have so many configuration options and
parameters that it would be harder to use than traversing "by hand".

But maybe you imagine something simpler than I do. Again, can I
suggest you post what you imagine the user documentation for the
function would look like, and then we'll be able to stop
misunderstanding each other?

Paul

On Wed, 21 Jul 2021 at 16:29, Sven Voigt <svenpvoigt@gmail.com> wrote:
>
> I could say the same thing about JSON dumps then and most itertools functions. The proposed functionality is in line with existing functionality and extends it to the case of nested data structures.
>
> On Wed, Jul 21, 2021 at 11:25 AM Chris Angelico <rosuav@gmail.com> wrote:
>>
>> On Thu, Jul 22, 2021 at 1:14 AM Sven Voigt <svenpvoigt@gmail.com> wrote:
>> >
>> > Paul,
>> >
>> > I agree that the mapping to a flat data structure might have limited use cases. However, like you said it is only one example. What I am proposing is a nested iteration tool that can map both keys and values to new keys and new values. It only considers nesting in dictionaries, lists, and tuples by default, but allows users to pass another function to continue searching for pointers in other types.
>> >
>>
>> This sounds like the sort of thing that's best coded up specifically
>> to your purposes. There'll be myriad small variants of this kind of
>> traversal, so it's easiest to just write the thing you want, rather
>> than try to get the standard library to support every variant.
>>
>> ChrisA
>> _______________________________________________
>> Python-ideas mailing list -- python-ideas@python.org
>> To unsubscribe send an email to python-ideas-leave@python.org
>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2IOA23Z33434YWPTQWDPMA5RGJBCPCRZ/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-leave@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/BRWPYXYXOFJAY7FKEGTFZO5T7XKBSCZ3/
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/UR52XKA2I6AWKCELIDODF5IVBHMHBBW7/
Code of Conduct: http://python.org/psf/codeofconduct/
--
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython