Skip to content

Commit 74888a0

Browse files
author
Irene Alvarado
committed
Add a json example
1 parent 3ef9e8a commit 74888a0

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

examples/json/data.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"date": "2021-04-15",
3+
"explanation": "Bright elliptical galaxy Messier 87 (M87) is home to the supermassive black hole captured by planet Earth's Event Horizon Telescope in the first ever image of a black hole. Giant of the Virgo galaxy cluster about 55 million light-years away, M87 is the large galaxy rendered in blue hues in this infrared image from the Spitzer Space telescope. Though M87 appears mostly featureless and cloud-like, the Spitzer image does record details of relativistic jets blasting from the galaxy's central region. Shown in the inset at top right, the jets themselves span thousands of light-years. The brighter jet seen on the right is approaching and close to our line of sight. Opposite, the shock created by the otherwise unseen receding jet lights up a fainter arc of material. Inset at bottom right, the historic black hole image is shown in context, at the center of giant galaxy and relativistic jets. Completely unresolved in the Spitzer image, the supermassive black hole surrounded by infalling material is the source of enormous energy driving the relativistic jets from the center of active galaxy M87.",
4+
"hdurl": "https://apod.nasa.gov/apod/image/2104/pia23122c-16.jpg",
5+
"media_type": "image",
6+
"service_version": "v1",
7+
"title": "The Galaxy, the Jet, and a Famous Black Hole",
8+
"url": "https://apod.nasa.gov/apod/image/2104/pia23122c-16_1067.jpg"
9+
}

examples/json/json-example.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { readJSON, writeJSON } from 'https://deno.land/x/[email protected]/mod.ts'
2+
3+
const json = await readJSON('./examples/json/data.json') as any
4+
5+
// a New custom json to save
6+
const newData = {
7+
'image': json.url
8+
}
9+
10+
await writeJSON('./examples/json/post-data.json', newData)

examples/json/post-data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"image":"https://apod.nasa.gov/apod/image/2104/pia23122c-16_1067.jpg"}

json.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export async function readJSON(path: string) {
2-
return JSON.parse(await Deno.readTextFile(path))
2+
const text = await Deno.readTextFile(path)
3+
return JSON.parse(text)
34
}
45

56
export async function writeJSON(path: string, data: any) {

0 commit comments

Comments
 (0)