• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ASON Parsing and Generation
2
3The [ASON utility](../reference/apis-arkts/js-apis-arkts-utils.md#arktsutilsason) is similar to the JSON utility provided by JavaScript. JSON is used to serialize (via **stringify**) and deserialize (via **parse**) JavaScript objects. In contrast, ASON provides serialization and deserialization capabilities for [Sendable objects](arkts-sendable.md). The **ASON.stringify** method converts an object to a string, and **ASON.parse** converts a string back to a Sendable object. This enables high-performance pass-by-reference of these objects between concurrent tasks.
4
5The **ASON.stringify** method can also convert Map and Set objects into strings. These include Map, Set, [collections.Map](../reference/apis-arkts/js-apis-arkts-collections.md#collectionsmap), [collections.Set](../reference/apis-arkts/js-apis-arkts-collections.md#collectionsset), [HashMap](../reference/apis-arkts/js-apis-hashmap.md#hashmap), and [HashSet](../reference/apis-arkts/js-apis-hashset.md#hashset).
6
7> **NOTE**
8>
9> By default, objects generated by **ASON.parse** are immutable Sendable objects that do not support adding or deleting properties. If you need to return objects with mutable layouts, you can specify the return type as MAP. In this case, all objects will be returned as [collections.Map](../reference/apis-arkts/js-apis-arkts-collections.md#collectionsmap) objects, which support adding and deleting properties.
10
11## Usage Example
12
13Use ASON interfaces to serialize and deserialize [Sendable objects](arkts-sendable.md).
14
15```ts
16import { ArkTSUtils, collections } from '@kit.ArkTS';
17
18ArkTSUtils.ASON.parse("{}")
19ArkTSUtils.ASON.stringify(new collections.Array(1, 2, 3))
20
21let options2: ArkTSUtils.ASON.ParseOptions = {
22    bigIntMode: ArkTSUtils.ASON.BigIntMode.PARSE_AS_BIGINT,
23    parseReturnType: ArkTSUtils.ASON.ParseReturnType.MAP,
24}
25let jsonText = '{"largeNumber":112233445566778899}';
26let map = ArkTSUtils.ASON.parse(jsonText, undefined, options2);
27ArkTSUtils.ASON.stringify(map);
28```
29<!-- @[example_serialize](https://gitee.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/AsonParsingGeneration.ets) -->
30