Blog
Sorry, your browser does not support inline SVG.

Koalas, JSON, r2.04, and AIM

K.S. Bhaskar

Koalas are some of the cutest animals around, but are listed as vulnerable by the International Union for Conservation of Nature and Natural Resources and listed as endangered by the Australian Department of Climate Change, Energy, the Environment and Water.

I wanted to explore a JSON dataset with the ZYDECODE command introduced in YottaDB r2.04. I found a JSON dataset of Koala records for twenty years to 2014 in Noosa Shire in Queensland, downloaded it, and renamed the file to NoosaShireKoalaRecordsto2014.json. I then loaded the raw data into the line local variable from which I parsed the JSON into the ^koala global variable. Note that ZYDECODE expects the top level of line to be the count of lines that make up the JSON file, which is one less than i, since the last value of i corresponds to when YottaDB encountered the end-of-file.

YDB>set file="/Distrib/Datasets/NoosaShireKoalaRecordsto2014.json" open file use file

YDB>for i=1:1 read line(i) quit:$zeof

YDB>use $principal set line=i-1 zydecode ^koala=line

YDB>

With some knowledge of the schema of the dataset, I used AIM to cross reference the number of koalas seen at each sighting, and determine the maximum number of these asocial animals that were observed at a sighting (which turns out to be 4).

YDB>kill sub set sub(1)="""features""",sub(3)="""properties""",sub(4)="""NUMBER_SEE"""

YDB>set koalanumx=$$XREFDATA^%YDBAIM("^koala",.sub,,,,,,1)

YDB>write $order(@koalanumx@(0,""),-1)
4
YDB>set x="" for  set x=$order(@koalanumx@(0,4,x)) quit:""=x  write x,!
480
744

YDB>

So what are these locations at which four koalas were sighted at a time?

YDB>for x=480,744 write ^koala("features",x,"properties","TOWN"),!
Doonan
Noosa Heads

YDB>

So, if I want to see koalas in Noosa Shire, Doonan and Noosa Heads are the places I should visit!

More importantly, I hope you can see how useful YottaDB r2.04’s ZYDECODE is when used with AIM to explore and analyze JSON datasets. YottaDB r2.04 also has a complementary ZYENCODE command to convert global and local [sub]trees to JSON, using an encoding that allows [sub]trees with values at roots to be converted to JSON and back without data loss using ZYDECODE. We look forward to hearing from you as you try the functionality


Credits

Published on April 16, 2026