# resource/jsonasset (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/resource/jsonasset/

JSON 데이터 애셋.

## JsonAsset extends TextAsset

JSON 데이터 애셋.

예제: JSON 파일 읽고 항목 보기

```js
import { JsonAsset } from "./build/vanilla.js";

const jsonAsset = new JsonAsset();
await jsonAsset.load("examples/timelineshowcase/assets/combo.timeline.json");
if (jsonAsset.isLoaded()) {
	const timelineKeys = Object.keys(jsonAsset.data);
	console.log(timelineKeys.length, jsonAsset.data.name);
}
```

- `data` (field, since 0.0.8): 해석한 JSON 값. (읽기 전이나 해석이 실패하면 null)
  - returns System.Object | null
- `constructor()` (constructor, since 0.0.8): 생성.
- `async load(assetPath)` (method, since 0.0.8): 비동기 애셋 로드.
  - `assetPath` string: JSON 파일 경로. (이미 읽혔으면 아무것도 하지 않는다)
  - returns Promise<void>: 다 읽고 해석하면 풀리는 프로미스. (받기나 해석이 실패하면 console.error 로 알리고 읽히지 않은 채로 거부된다)
- `loadFromBytes(assetPath, bytes)` (method, since 0.4.0): 이미 가진 바이트로 읽기. (UTF-8 JSON, 해석하지 못하면 알리고 읽히지 않은 것으로 둔다. load 와 같다)
  - `assetPath` string: getAssetPath 에 쓸 이름.
  - `bytes` ArrayBuffer | ArrayBufferView: JSON 파일의 바이트. (UTF-8)
- `unload()` (method, since 0.0.8): 애셋 언로드.
