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

1.0.0-alpha.7 • Public • Published

@helixnetwork/extract-json

Extracts JSON encoded messages from signature message fragments.

Installation

Install using npm:

npm install @helixnetwork/extract-json

or using yarn:

yarn add @helixnetwork/extract-json

API Reference

<a name="module_extract-json..extractJson"></a>

extract-json~extractJson(bundle)

Param Type
bundle array

Takes a bundle as input and from the signatureMessageFragments extracts the correct JSON data which was encoded and sent with the transaction. Supports the following forms of JSON encoded values:

  • "{ \"message\": \"hello\" }"\
  • "[1, 2, 3]"
  • "true", "false" & "null"
  • `""hello""
  • 123

Example

try {
  const msg = JSON.parse(extractJson(bundle))
} catch (err) {
  err.msg == errors.INVALID_BUNDLE
  // Invalid bundle or invalid encoded JSON
}

Example
Example with getBundle:

getBundle(tailHash)
  .then(bunlde => {
     const msg = JSON.parse(extractJson(bundle))
     // ...
  })
  .catch((err) => {
     // Handle network & extraction errors
  })

Package Sidebar

Install

npm i @helixnetwork/extract-json

Weekly Downloads

9

Version

1.0.0-alpha.7

License

MIT

Unpacked Size

74.5 kB

Total Files

22

Last publish

Collaborators

  • dzlzv
  • dad1x
  • fsbbn
  • dnck
  • dt93
  • ofo42