calculate transaction ID TXID from JSON or raw transaction consider an offline transaction that has not been posted yet, created through a method such as here:

http://brainwallet.org/#tx

a) how could I calculate the transaction ID from the raw transaction?
b) how could I calculate the transaction ID from the JSON transaction?
Both the reference client (Bitcoin-QT) and a service like http://brainwallet.org/ show the transaction ID after signing but before the transaction is broadcast. 

Take for example, this valid binary transaction:

01000000017a06ea98cd40ba2e3288262b28638cec5337c1456aaf5eedc8e9e5a20f062bdf000000008b48304502200addea57dd4c2871357165ed6d2bc94b117e322918073ac4c66d535637e74600022100dfaa0dce9e2e61aa2867c87fadca4e0fa3c70e9852a4689b3ef24b3f94809b4a014104e0ba531dc5d2ad13e2178196ade1a23989088cfbeddc7886528412087f4bff2ebc19ce739f25a63056b6026a269987fcf5383131440501b583bab70a7254b09effffffff01b02e052a010000001976a9142dbde30815faee5bf221d6688ebad7e12f7b2b1a88ac00000000


In JSON it decodes to:

{
    "txid" : "46b690f548f6eb70dca7fb2020ff4be369c42f3ea2375fd3f6b34890b640f8e9",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        { [... snipped ...]}
        }
    ]
}


With the transaction ID in the first key. If you were doing the signing yoruself, the TXID is literally a double SHA256 hash of the raw transaction. There's some more information about raw transactions on the wiki.