DataHandler.JSONDataHandler

Types

PariahJSON

Represents a JSON file on disk along with its parsed data.

  • Fields:
    • string FileName (read-only): The name of the JSON file (without extension).
    • string FilePath (internal set): The directory path where the file resides.
    • JsonObject Data (read-only): The parsed JSON content.
  • Constructor:
    PariahJSON(string fileName, string filePath, JsonObject data)
    Initializes a new instance with the given file name, file path, and JSON data.

Methods

CreateJsonFile(string Filename, string FileLocation, JsonObject defaultData)

Creates a new .json file containing the provided default data.

  • Returns: Task
  • Exceptions: Throws if directory doesn't exist or file already exists.

LoadJsonFile(string Filename, string FileLocation)

Loads and parses an existing .json file into a PariahJSON struct.

  • Returns: Task
  • Exceptions: Throws if directory/file missing or corrupted.

AddToJson(PariahJSON JsonData, string dataName, object data, SecureData Key)

Encrypts and adds a new field to the in-memory JSON using DataEncryptions.PackData.

  • Parameters:
    • Key: Required SecureData — must not be null (throws "Invalid Key Input" if null)
  • Returns: Task with updated in-memory data (does not save to disk)

DeletefromJson(PariahJSON JsonData, string dataName)

Removes a property from the in-memory JSON.

  • Returns: PariahJSON (synchronous)

UpdateJson(PariahJSON JsonData, string dataName, object data, SecureData Key)

Replaces an existing encrypted field with new data.

  • Parameters:
    • Key: Required SecureData — must not be null
  • Returns: Task (does not save to disk)

GetVariable(PariahJSON JsonData, string dataName, SecureData Key)

Retrieves and decrypts a stored field using DataEncryptions.UnpackData.

  • Parameters:
    • Key: Required SecureData — must not be null
  • Returns: Task — decrypted value
  • Exceptions: Throws if property missing, not a string, or decryption fails

CheckIfVariableExists(PariahJSON JsonData, string dataName)

Checks whether a given property exists and contains an encrypted string.

  • Returns: Task

SaveJson(PariahJSON JsonData)

Serializes and overwrites the original .json file on disk using BinaryConverter + EasyPQC.WriteAllBytesAsync.

  • Returns: Task
  • Exceptions: Throws if directory/file gone or write fails