@iota/extract-json
v1.0.0-beta.30
Published
Extracts JSON encoded messages from signature message fragments
Downloads
53
Readme
@iota/extract-json
Extracts JSON encoded messages from signature message fragments.
Installation
Install using npm:
npm install @iota/extract-json
or using yarn:
yarn add @iota/extract-json
API Reference
extract-json.extractJson(bundle)
Summary: Extracts JSON from transactions.
Throws:
- errors.INVALID_BUNDLE : Make sure that the
bundle
argument is an array of transaction trytes. - errors.INVALID_JSON : Make sure that the transactions'
signatureMessageFragment
fields contain valid JSON.
| Param | Type | Description | | --- | --- | --- | | bundle | array | Transaction trytes |
This method takes the signatureMessageFragment
fields of all the given transaction trytes, and tries to extract any JSON data that's in them.
The following forms of JSON-encoded values are supported:
"{ \"message\": \"hello\" }"
"[1, 2, 3]"
"true"
,"false"
&"null"
"\"hello\""
123
Related methods
To get a bundle's transaction trytes from the Tangle, use the getBundle()
method.
Returns: string | number | null - The JSON data in the transactions
Example
try {
const json = JSON.parse(extractJson(bundle))
} catch (error) {
console.log(error);
}