@iota/extract-json
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.30 • Public • Published

@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);
}

Install

npm i @iota/extract-json

DownloadsWeekly Downloads

52

Version

1.0.0-beta.30

License

MIT

Unpacked Size

62.1 kB

Total Files

21

Last publish

Collaborators

  • tuditi
  • msarcevic
  • braniota
  • lmoe
  • domschiener
  • lexerr
  • martyniota
  • nothingismagick
  • laumair
  • iota_ci
  • rubenkoch
  • brord