Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/Profile.cpp (C++)

Code before:
    if (const auto guid{ JsonUtils::GetValueForKey<std::optional<GUID>>(json, GuidKey) })
    {
        return { guid.value() };
    }

    const auto name{ JsonUtils::GetValueForKey<hstring>(json, NameKey) };
    const auto source{ JsonUtils::GetValueForKey<hstring>(json, SourceKey) };

    return Profile::_GenerateGuidForProfile(name, source);
}

// Method Description:
// - Create a new serialized JsonObject from an instance of this class
// Arguments:
// - <none>
// Return Value:
// - the JsonObject representing this instance
Json::Value Profile::ToJson() const
{
    // Initialize the json with the appearance settings
    Json::Value json{ winrt::get_self<implementation::AppearanceConfig>(_DefaultAppearance)->ToJson() };

    // GH #9962:
    //   If the settings.json was missing, when we load the dynamic profiles, they are completely empty.
    //   This caused us to serialize empty profiles "{}" on accident.
    bool writeBasicSettings{ !Source().empty() };

    // Profile-specific Settings
    JsonUtils::SetValueForKey(json, NameKey, writeBasicSettings ? Name() : _Name);
    JsonUtils::SetValueForKey(json, GuidKey, writeBasicSettings ? Guid() : _Guid);
    JsonUtils::SetValueForKey(json, HiddenKey, writeBasicSettings ? Hidden() : _Hidden);
    JsonUtils::SetValueForKey(json, SourceKey, writeBasicSettings ? Source() : _Source);

    // TODO:MSFT:20642297 - Use a sentinel value (-1) for "Infinite scrollback"
    JsonUtils::SetValueForKey(json, HistorySizeKey, _HistorySize);
    JsonUtils::SetValueForKey(json, SnapOnInputKey, _SnapOnInput);
    JsonUtils::SetValueForKey(json, AltGrAliasingKey, _AltGrAliasing);
    JsonUtils::SetValueForKey(json, TabTitleKey, _TabTitle);

    // Control Settings
    JsonUtils::SetValueForKey(json, FontWeightKey, _FontWeight);
    JsonUtils::SetValueForKey(json, ConnectionTypeKey, _ConnectionType);
    JsonUtils::SetValueForKey(json, CommandlineKey, _Commandline);
    JsonUtils::SetValueForKey(json, FontFaceKey, _FontFace);
    JsonUtils::SetValueForKey(json, FontSizeKey, _FontSize);
    JsonUtils::SetValueForKey(json, AcrylicTransparencyKey, _AcrylicOpacity);
    JsonUtils::SetValueForKey(json, UseAcrylicKey, _UseAcrylic);
    JsonUtils::SetValueForKey(json, SuppressApplicationTitleKey, _SuppressApplicationTitle);
    JsonUtils::SetValueForKey(json, CloseOnExitKey, _CloseOnExit);

    // PermissiveStringConverter is unnecessary for serialization

Review comment (suggestion):
```suggestion
    const bool writeBasicSettings{ !Source().empty() };
```

Code after:
    if (const auto guid{ JsonUtils::GetValueForKey<std::optional<GUID>>(json, GuidKey) })
    {
        return { guid.value() };
    }

    const auto name{ JsonUtils::GetValueForKey<hstring>(json, NameKey) };
    const auto source{ JsonUtils::GetValueForKey<hstring>(json, SourceKey) };

    return Profile::_GenerateGuidForProfile(name, source);
}

// Method Description:
// - Create a new serialized JsonObject from an instance of this class
// Arguments:
// - <none>
// Return Value:
// - the JsonObject representing this instance
Json::Value Profile::ToJson() const
{
    // Initialize the json with the appearance settings
    Json::Value json{ winrt::get_self<implementation::AppearanceConfig>(_DefaultAppearance)->ToJson() };

    // GH #9962:
    //   If the settings.json was missing, when we load the dynamic profiles, they are completely empty.
    //   This caused us to serialize empty profiles "{}" on accident.
    const bool writeBasicSettings{ !Source().empty() };

    // Profile-specific Settings
    JsonUtils::SetValueForKey(json, NameKey, writeBasicSettings ? Name() : _Name);
    JsonUtils::SetValueForKey(json, GuidKey, writeBasicSettings ? Guid() : _Guid);
    JsonUtils::SetValueForKey(json, HiddenKey, writeBasicSettings ? Hidden() : _Hidden);
    JsonUtils::SetValueForKey(json, SourceKey, writeBasicSettings ? Source() : _Source);

    // TODO:MSFT:20642297 - Use a sentinel value (-1) for "Infinite scrollback"
    JsonUtils::SetValueForKey(json, HistorySizeKey, _HistorySize);
    JsonUtils::SetValueForKey(json, SnapOnInputKey, _SnapOnInput);
    JsonUtils::SetValueForKey(json, AltGrAliasingKey, _AltGrAliasing);
    JsonUtils::SetValueForKey(json, TabTitleKey, _TabTitle);

    // Control Settings
    JsonUtils::SetValueForKey(json, FontWeightKey, _FontWeight);
    JsonUtils::SetValueForKey(json, ConnectionTypeKey, _ConnectionType);
    JsonUtils::SetValueForKey(json, CommandlineKey, _Commandline);
    JsonUtils::SetValueForKey(json, FontFaceKey, _FontFace);
    JsonUtils::SetValueForKey(json, FontSizeKey, _FontSize);
    JsonUtils::SetValueForKey(json, AcrylicTransparencyKey, _AcrylicOpacity);
    JsonUtils::SetValueForKey(json, UseAcrylicKey, _UseAcrylic);
    JsonUtils::SetValueForKey(json, SuppressApplicationTitleKey, _SuppressApplicationTitle);
    JsonUtils::SetValueForKey(json, CloseOnExitKey, _CloseOnExit);

    // PermissiveStringConverter is unnecessary for serialization