0

How take a nested object and flatten it with delimited keys? Other words, are there any C# library similar to "flat" https://www.npmjs.com/package/flat ?

Example:

var obj1 = {
    o1p1: "o1p1_Value",
    o1p2: "o1p2_Value"
};

var obj2 = {
    o2p1: "o2p1_Value",
    o2p2: obj1
};

var obj3 = flatten.flatten(obj2);

Here obj3:

{ o2p1: 'o2p1_Value',
  'o2p2.o1p1': 'o1p1_Value',
  'o2p2.o1p2': 'o1p2_Value' }
  • I'd suggest looking a JSON libraries to see if any have this ability. Maybe this question will help http://stackoverflow.com/questions/30389990/how-to-flatten-some-json-with-json-net or this one http://stackoverflow.com/questions/31046448/json-serialisation-how-to-flatten-nested-object-structures-using-json-net-newt – juharr Apr 13 '17 at 14:53
  • I don't think that you can find a magical tool for doing this in c# since the selectmany linq will work on IEnumerable – BRAHIM Kamel Apr 13 '17 at 15:19

0 Answers0