1.0.0 • Published 5 years ago
@keupoz/typescript-json v1.0.0
Typed JSON
A library inspired by Gson Java library.
Install
npm i @keupoz/typescript-jsonUsage
Usage is pretty simple. To create an instance of Json element use JsonElement.from(json).
import { JsonElement } from "@keupoz/typescript-json";
const json = JsonElement.from({ a: 1, b: 2, c: 3 });Methods
All getAsJson{type} methods may return JsonNull instance.
JsonElement
JsonElement.from(value: any): inits a corresponding JsonElement subclass instance.JsonElement#isJsonArray(): is a typeguard which tells that current instance isJsonArray.JsonElement#isJsonNull(): is a typeguard which tells that current instance isJsonNull.JsonElement#isJsonObject(): is a typeguard which tells that current instance isJsonObject.JsonElement#isJsonPrimitve(): is a typeguard which tells that current instance isJsonPrimitve.
JsonArray
JsonArray#getAsJsonArray(index: number): returns value at specified index asJsonArray.JsonArray#getAsJsonObject(index: number): returns value at specified index asJsonObject.JsonArray#getAsJsonPrimitive(index: number): returns value at specified index asJsonPrimitive.JsonArray#getAsJsonArrayTuple(): returns array ofJsonArrayinstances.JsonArray#getAsJsonObjectTuple(): returns array ofJsonObjectinstances.JsonArray#getAsJsonPrimitiveTuple(): returns array ofJsonPrimitiveinstances.
JsonObject
JsonObject#getAsJsonArray(key: string): returns specified property asJsonArray.JsonObject#getAsJsonObject(key: string): returns specified property asJsonObject.JsonObject#getAsJsonPrimitive(key: string): returns specified property asJsonPrimitive.
JsonPrimitive
JsonPrimitive#isBoolean(): returns boolean value representing if current primitive is boolean.JsonPrimitive#isNumber(): returns boolean value representing if current primitive is number.JsonPrimitive#isString(): returns boolean value representing if current primitive is string.JsonPrimitive#getAsBoolean(): returns current primitive as boolean.JsonPrimitive#getAsNumber(): returns current primitive as number.JsonPrimitive#getAsString(): returns current primitive as string.
1.0.0
5 years ago