Skip to content

Remove unnecessary JSON parsing in BackupJob #201

@JamieMagee

Description

@JamieMagee

The BackupData project has a redundant JSON parsing step when processing MongoDB documents:

BsonDocument → ToString() → JSON string → Parse into JObject → Extract fields → ToString() → Upload

The JObject is only used to extract two fields (_id and _meta.updated). We can read these directly from the BsonDocument and skip the parsing entirely:

// Before
var jObject = JsonConvert.DeserializeObject(document.ToString()) as JObject;
var blobName = jObject["_id"]?.ToString();
var updated = jObject["_meta"]?["updated"]?.ToString();
var json = jObject.ToString();

// After
var blobName = document["_id"].AsString;
var updated = document["_meta"]["updated"].ToUniversalTime();
var json = document.ToJson();

This removes the Newtonsoft.Json dependency from the production build and eliminates a redundant parse/serialize cycle. The output format stays the same (JSON files in blob storage), so there's no breaking change for consumers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions