#1 Today 07:56:20

tfopc
Member
Registered: 2024-01-08
Posts: 41

FlattenFromNestedObjects only nesting one(root) level

Hi ab,

i played around with the new yaml parser (thanks, zen010101 and ab for the addition)

i try to do some helper to migrate yaml/json -> ini-files and back.

For saving json/yaml in the ini need to flatten the nested objects...

So i catched this ...

Doc.InitJson('{"a":{"b":1,"c":1},d:3}');
Doc.FlattenFromNestedObjects('.');
CheckEqual(Doc.ToJson, '{"a.b":1,"a.c":1,"d":3}');

I assume that “FlattenFromNestedObjects” completely flattens the nested structures.

So that this test would succeed.

Doc.InitJson('{"a":{"b":{"bb":2},"c":1},d:3}');
Doc.FlattenFromNestedObjects('.');
CheckEqual(Doc.ToJson, '{"a.b.bb":2,"a.c":1,"d":3}');

But at the moment it only nesting the root - level:

{"a":{"b":{"bb":2},"c":1},d:3} -> {"a.b":{"bb":2},"a.c":1,"d":3}

So this test also fails.

Doc.InitJson('{"a":{"b":{"bb":2},"c":1},d:3}');
Doc.FlattenFromNestedObjects('.');
CheckNotEqual(Doc.ToJson, '{"a.b":{"bb":2},"a.c":1,"d":3}');

Is this expected?

Thank you.

Tobias

Offline

#2 Today 09:04:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,445
Website

Re: FlattenFromNestedObjects only nesting one(root) level

Yes, it only flatten the root level.
It was on purpose, because it was designed and used in a specific case  of a generic single level key/value property dictionary context.

For INI, you don't need to 'flatten' the nested objects.
You could use dedicated sections per object.
This is what mORMot IniToObject() does - and TSynJsonFileSettings.

Offline

Board footer

Powered by FluxBB