4 ms·
I use AWS. I want to take my JSON, and store it in Dynamo. I need to convert every object object embedded in my top object to a {"M" : {...}} structure, and e
by lostcolony 11y ago
I use AWS.
I want to take my JSON, and store it in Dynamo.
I need to convert every object object embedded in my top object to a {"M" : {...}} structure, and every array/list to a {"L" : [...]} structure. So something like -
{"a" : {"b" : [1]}} should become {"a" : {"M" : {"b" : {"L" : ["N" : "1"]}}}}.
The easiest way to write one function that can handle that in a generic way, no matter how complicated the data structure (barring hitting the stack limit), is recursion.
- jsprogrammer 11y agoEh. I don't think writing a custom stack implementation would be any more difficult and you'd get to scale to the memory of your machine rather than your language's runtime.
- lostcolony 11y agoI'd love to see the code for that if you've got it (I have a recursive version in Javascript). Because the recursive one is really simple to read, intuitively grasp what is going on, confirm is correct, test, modify, etc. And rewriting it to use a stack, while possible, feels harder to me to think up, reason about, and no matter how I try comes out uglier. I haven't spent a lot of time on it, mind you (in part because the recursive one hits everything I care about), but I'd love to see one as elegant written iteratively.