cvToJSON
Converts a Clarity value to a JSON-serializable object. Includes the type name and value, with integers represented as strings for JSON compatibility.
Usage
import { cvToJSON, Cl } from '@stacks/transactions';
cvToJSON(Cl.uint(100));
// { type: 'uint', value: '100' }
cvToJSON(Cl.ok(Cl.uint(100)));
// { type: '(response uint UnknownType)', value: { type: 'uint', value: '100' }, success: true }
cvToJSON(Cl.tuple({ name: Cl.stringAscii('hello'), id: Cl.uint(1) }));
// { type: '(tuple ...)', value: { name: { type: '...', value: 'hello' }, id: { type: 'uint', value: '1' } } }Notes
Integers are converted to strings for JSON compatibility (unlike
cvToValuewhich returnsbigint).Response types include a
successboolean property.
Signature
Returns
any
A JSON-serializable object with type and value properties.
Parameters
val (required)
Type:
ClarityValue
The Clarity value to convert.
Last updated
Was this helpful?