@iota/extract-json v1.0.0-beta.30
@iota/extract-json
Extracts JSON encoded messages from signature message fragments.
Installation
Install using npm:
npm install @iota/extract-jsonor using yarn:
yarn add @iota/extract-jsonAPI Reference
extract-json.extractJson(bundle)
Summary: Extracts JSON from transactions.
Throws:
- errors.INVALID_BUNDLE : Make sure that the
bundleargument is an array of transaction trytes. - errors.INVALID_JSON : Make sure that the transactions'
signatureMessageFragmentfields 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);
}5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago