Skip to main content

JSON values (AnyJSON)

AnyJSON represents a JSON value: a string, number, boolean, null, array, or object. Arrays and objects can contain nested JSON values.

import { type AnyJSON, type HybridObject, iOS } from 'nitro-core'

@iOS(...)
export declare class Fetch extends HybridObject {
get(url: string): AnyJSON
}

When JS values or objects are passed to native, AnyJSON serializes them via JSON.stringify(...). You can decode JSON using platform decoders, or separate JSON libraries.

When AnyJSON values are returned to JS, they are parsed via JSON.parse(...) to construct JS values or objects.

Use custom structs instead​

Prefer typed structs when the fields are known. They provide compile-time checks, support every type (bigint, functions, other Hybrid Objects, ...) and are faster because they avoid JSON serialization.