Package detail

hex2json

Convert hex to json

hex, json, web3, decode

readme

hex2json

Decode hex data into a JSON object.

Overview

hex2json is a simple library that decodes hex strings and extracts JSON data. This library is compatible with both CommonJS and ES6 module formats.

Installation

Install the library using npm:

npm install hex2json

Usage

Common JS

const { decodeHexToJson } = require('hex2json');

const hexStr = "0x000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006f7b227469746c65223a22222c227375625f7469746c65223a2261222c2268746d6c5f636f6e74656e74223a223c703e613c2f703e5c6e222c22696d616765223a2261222c226372656174696f6e5f74696d65223a22323032342d30352d31345432333a35373a30352e3230375a227d0000000000000000000000000000000000";

try {
    const parsedData = decodeHexToJson(hexStr);
    console.log("Parsed JSON:", parsedData);
} catch (error) {
    console.error(error.message);
}

Es6

import { decodeHexToJson } from 'hex2json';

const hexStr = "0x000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006f7b227469746c65223a22222c227375625f7469746c65223a2261222c2268746d6c5f636f6e74656e74223a223c703e613c2f703e5c6e222c22696d616765223a2261222c226372656174696f6e5f74696d65223a22323032342d30352d31345432333a35373a30352e3230375a227d0000000000000000000000000000000000";

try {
    const parsedData = decodeHexToJson(hexStr);
    console.log("Parsed JSON:", parsedData);
} catch (error) {
    console.error(error.message);
}