aui icon indicating copy to clipboard operation
aui copied to clipboard

Rethink AJson object container approach

Open Alex2772 opened this issue 1 year ago • 3 comments

This discussion is started in #261.

Summary: we need a way to keep order of fields in AJson (Json::Object).

I generally agree that order should be kept in json objects, but unordered_map does not guarantee the persistence of order. Another container should be used. Even std::vector<std::pair<AString, AJson>> seems acceptable. Furthermore, you may take a look at ASmallVector.

nlohmann json uses std::map as the default container for object. It also offers alternative object type which is implemented as vector of string-json pair. https://json.nlohmann.me/features/object_order/

Originally posted by @Alex2772 in https://github.com/aui-framework/aui/issues/261#issuecomment-2016961465

@na2axl

Alex2772 avatar Mar 25 '24 14:03 Alex2772

I've added Google Benchmark initial support (#262). I'll check for performance of vector variant in my spare time.

Alex2772 avatar Mar 26 '24 02:03 Alex2772

For this maybe a AJsonObject class which extends AVector<std::pair<AString, AJson>> and adds index operators for AString ?

na2axl avatar Apr 16 '24 12:04 na2axl

For this maybe a AJsonObject class which extends AVector<std::pair<AString, AJson>> and adds index operators for AString ?

I think I will come up with something like this.

Alex2772 avatar Apr 16 '24 19:04 Alex2772

Hey @Alex2772, I don't know if you still have plans for this but I can confirm the new AJsonObject implementation works fine for my use case 🎉

na2axl avatar Jun 26 '24 01:06 na2axl

Hi @na2axl, great news! There are no extra work planned on this, so we can close this as resolved.

Alex2772 avatar Jun 26 '24 03:06 Alex2772