beancount
    Preparing search index...

    Function deserializeNode

    • Deserializes a single node from its JSON representation.

      This function takes a plain JavaScript object (typically from JSON.parse) and reconstructs the appropriate Node subclass instance. It validates the input and provides helpful error messages for common issues.

      Parameters

      • nodeData: Record<string, unknown>

        Plain object containing node data with a 'type' field

      Returns Node

      An Node instance of the appropriate subclass

      If the node data is invalid:

      • Missing or invalid 'type' field
      • Unknown node type
      • Invalid node structure (errors from Node.fromJSONData)

      Deserializing a simple node:

      const nodeData = {
      type: 'open',
      date: '2024-01-01',
      account: 'Assets:Checking'
      }
      const node = deserializeNode(nodeData)
      console.log(node.type) // 'open'

      Deserializing from JSON.parse:

      const json = '{"type":"balance","date":"2024-01-02","account":"Assets:Checking","amount":"100","currency":"USD"}'
      const nodeData = JSON.parse(json)
      const node = deserializeNode(nodeData)