161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file
1861847f8eSopenharmony_ci * @kit ArkTS
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ci/**
2261847f8eSopenharmony_ci * JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null.
2361847f8eSopenharmony_ci *
2461847f8eSopenharmony_ci * @namespace json
2561847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang
2661847f8eSopenharmony_ci * @crossplatform
2761847f8eSopenharmony_ci * @atomicservice
2861847f8eSopenharmony_ci * @since 12
2961847f8eSopenharmony_ci */
3061847f8eSopenharmony_cideclare namespace json {
3161847f8eSopenharmony_ci  /**
3261847f8eSopenharmony_ci   * The type of conversion result function.
3361847f8eSopenharmony_ci   *
3461847f8eSopenharmony_ci   * @typedef { function } Transformer
3561847f8eSopenharmony_ci   * @param { Object } this - The object to which the parsed key value pair belongs.
3661847f8eSopenharmony_ci   * @param { string } key - Attribute name.
3761847f8eSopenharmony_ci   * @param { Object } value - The value of the parsed key value pair.
3861847f8eSopenharmony_ci   * @returns { Object | undefined | null } Return the modified object or undefined or null.
3961847f8eSopenharmony_ci   * @syscap SystemCapability.Utils.Lang
4061847f8eSopenharmony_ci   * @atomicservice
4161847f8eSopenharmony_ci   * @since 12
4261847f8eSopenharmony_ci   */
4361847f8eSopenharmony_ci  type Transformer = (this: Object, key: string, value: Object) => Object | undefined | null
4461847f8eSopenharmony_ci
4561847f8eSopenharmony_ci  /**
4661847f8eSopenharmony_ci   * Converts a JavaScript Object Notation (JSON) string into an Object or null.
4761847f8eSopenharmony_ci   *
4861847f8eSopenharmony_ci   * @param { string } text - A valid JSON string.
4961847f8eSopenharmony_ci   * @param { Transformer } [reviver] - A function that transforms the results.
5061847f8eSopenharmony_ci   * @param {ParseOptions} options - The config of parse.
5161847f8eSopenharmony_ci   * @returns { Object | null } Return an Object, array, string, number, boolean, or null value corresponding to JSON text.
5261847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
5361847f8eSopenharmony_ci   * @syscap SystemCapability.Utils.Lang
5461847f8eSopenharmony_ci   * @crossplatform
5561847f8eSopenharmony_ci   * @atomicservice
5661847f8eSopenharmony_ci   * @since 12
5761847f8eSopenharmony_ci   */
5861847f8eSopenharmony_ci  function parse(text: string, reviver?: Transformer, options?: ParseOptions): Object | null;
5961847f8eSopenharmony_ci
6061847f8eSopenharmony_ci  /**
6161847f8eSopenharmony_ci   * Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
6261847f8eSopenharmony_ci   *
6361847f8eSopenharmony_ci   * @param { Object } value - A JavaScript value, usually an Object or array.
6461847f8eSopenharmony_ci   * @param { (number | string)[] | null } [replacer] - An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringify.
6561847f8eSopenharmony_ci   * @param { string | number } [space] - Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
6661847f8eSopenharmony_ci   * @returns { string } Return a JSON text.
6761847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
6861847f8eSopenharmony_ci   * @syscap SystemCapability.Utils.Lang
6961847f8eSopenharmony_ci   * @crossplatform
7061847f8eSopenharmony_ci   * @atomicservice
7161847f8eSopenharmony_ci   * @since 12
7261847f8eSopenharmony_ci   */
7361847f8eSopenharmony_ci  function stringify(value: Object, replacer?: (number | string)[] | null, space?: string | number): string
7461847f8eSopenharmony_ci
7561847f8eSopenharmony_ci  /**
7661847f8eSopenharmony_ci   * Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
7761847f8eSopenharmony_ci   *
7861847f8eSopenharmony_ci   * @param { Object } value - A JavaScript value, usually an Object or array.
7961847f8eSopenharmony_ci   * @param { Transformer } [replacer] - A function that transforms the results.
8061847f8eSopenharmony_ci   * @param { string | number } [space] - Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
8161847f8eSopenharmony_ci   * @returns { string } Return a JSON text.
8261847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
8361847f8eSopenharmony_ci   * @syscap SystemCapability.Utils.Lang
8461847f8eSopenharmony_ci   * @crossplatform
8561847f8eSopenharmony_ci   * @atomicservice
8661847f8eSopenharmony_ci   * @since 12
8761847f8eSopenharmony_ci   */
8861847f8eSopenharmony_ci  function stringify(value: Object, replacer?: Transformer, space?: string | number): string;
8961847f8eSopenharmony_ci
9061847f8eSopenharmony_ci  /**
9161847f8eSopenharmony_ci   * Checks whether the object parsed from a JSON string contains the property.
9261847f8eSopenharmony_ci   *
9361847f8eSopenharmony_ci   * @param { object } obj - The object parsed from a JSON string.
9461847f8eSopenharmony_ci   * @param { string } property - Determine whether the object contains the property.
9561847f8eSopenharmony_ci   * @returns { boolean } Return true if the key is in the object, otherwise return false.
9661847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.
9761847f8eSopenharmony_ci   * @syscap SystemCapability.Utils.Lang
9861847f8eSopenharmony_ci   * @crossplatform
9961847f8eSopenharmony_ci   * @atomicservice
10061847f8eSopenharmony_ci   * @since 12
10161847f8eSopenharmony_ci   */
10261847f8eSopenharmony_ci  function has(obj: object, property: string): boolean;
10361847f8eSopenharmony_ci
10461847f8eSopenharmony_ci  /**
10561847f8eSopenharmony_ci   * Removes a property from the object parsed from a JSON string.
10661847f8eSopenharmony_ci   *
10761847f8eSopenharmony_ci   * @param { object } obj - The object parsed from a JSON string.
10861847f8eSopenharmony_ci   * @param { string } property - The property to be removed.
10961847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.
11061847f8eSopenharmony_ci   * @syscap SystemCapability.Utils.Lang
11161847f8eSopenharmony_ci   * @crossplatform
11261847f8eSopenharmony_ci   * @atomicservice
11361847f8eSopenharmony_ci   * @since 12
11461847f8eSopenharmony_ci   */
11561847f8eSopenharmony_ci  function remove(obj: object, property: string): void;
11661847f8eSopenharmony_ci
11761847f8eSopenharmony_ci  /**
11861847f8eSopenharmony_ci   * Enum defining modes for handling bigint.
11961847f8eSopenharmony_ci   *
12061847f8eSopenharmony_ci   * @enum { number } BigIntMode
12161847f8eSopenharmony_ci   * @syscap SystemCapability.Utils.Lang
12261847f8eSopenharmony_ci   * @crossplatform
12361847f8eSopenharmony_ci   * @atomicservice
12461847f8eSopenharmony_ci   * @since 12
12561847f8eSopenharmony_ci   */
12661847f8eSopenharmony_ci  const enum BigIntMode {
12761847f8eSopenharmony_ci    /**
12861847f8eSopenharmony_ci     * BigInt is not supported.
12961847f8eSopenharmony_ci     *
13061847f8eSopenharmony_ci     * @syscap SystemCapability.Utils.Lang
13161847f8eSopenharmony_ci     * @crossplatform
13261847f8eSopenharmony_ci     * @atomicservice
13361847f8eSopenharmony_ci     * @since 12
13461847f8eSopenharmony_ci     */
13561847f8eSopenharmony_ci    DEFAULT = 0,
13661847f8eSopenharmony_ci    /**
13761847f8eSopenharmony_ci     * Parse as BigInt when number less than -(2^53 – 1) or greater than (2^53 – 1).
13861847f8eSopenharmony_ci     *
13961847f8eSopenharmony_ci     * @syscap SystemCapability.Utils.Lang
14061847f8eSopenharmony_ci     * @crossplatform
14161847f8eSopenharmony_ci     * @atomicservice
14261847f8eSopenharmony_ci     * @since 12
14361847f8eSopenharmony_ci     */
14461847f8eSopenharmony_ci    PARSE_AS_BIGINT = 1,
14561847f8eSopenharmony_ci    /**
14661847f8eSopenharmony_ci     * All numbers parse as BigInt.
14761847f8eSopenharmony_ci     *
14861847f8eSopenharmony_ci     * @syscap SystemCapability.Utils.Lang
14961847f8eSopenharmony_ci     * @crossplatform
15061847f8eSopenharmony_ci     * @atomicservice
15161847f8eSopenharmony_ci     * @since 12
15261847f8eSopenharmony_ci     */
15361847f8eSopenharmony_ci    ALWAYS_PARSE_AS_BIGINT = 2,
15461847f8eSopenharmony_ci  }
15561847f8eSopenharmony_ci
15661847f8eSopenharmony_ci  /**
15761847f8eSopenharmony_ci   * Parse's options
15861847f8eSopenharmony_ci   *
15961847f8eSopenharmony_ci   * @typedef ParseOptions
16061847f8eSopenharmony_ci   * @syscap SystemCapability.Utils.Lang
16161847f8eSopenharmony_ci   * @crossplatform
16261847f8eSopenharmony_ci   * @atomicservice
16361847f8eSopenharmony_ci   * @since 12
16461847f8eSopenharmony_ci   */
16561847f8eSopenharmony_ci  interface ParseOptions {
16661847f8eSopenharmony_ci    /**
16761847f8eSopenharmony_ci    * Enum defining modes for handling bigint.
16861847f8eSopenharmony_ci    * @type { BigIntMode }
16961847f8eSopenharmony_ci    * @syscap SystemCapability.Utils.Lang
17061847f8eSopenharmony_ci    * @crossplatform
17161847f8eSopenharmony_ci    * @atomicservice
17261847f8eSopenharmony_ci    * @since 12
17361847f8eSopenharmony_ci    */
17461847f8eSopenharmony_ci    bigIntMode: BigIntMode;
17561847f8eSopenharmony_ci  }
17661847f8eSopenharmony_ci}
17761847f8eSopenharmony_ciexport default json;