beancount
    Preparing search index...

    Function deserializeNodeFromString

    • Deserializes a single node from a JSON string.

      This function parses a JSON string containing an node object and reconstructs the appropriate Node subclass instance.

      Parameters

      • jsonString: string

        JSON string containing an node object

      Returns Node

      An Node instance of the appropriate subclass

      If the JSON is invalid or node cannot be deserialized:

      • Invalid JSON syntax
      • JSON does not contain an object
      • Node validation errors (see deserializeNode)

      Deserializing from a JSON string:

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

      Roundtrip serialization:

      const original = Open.fromString('2024-01-01 open Assets:Checking')
      const json = JSON.stringify(original.toJSON())
      const deserialized = deserializeNodeFromString(json)
      // deserialized equals original