Jason, alsoknownasJavaScriptobjectnotation, issimply a datarepresentationformatverysimilartoXMLoryammer.
It's usedwidelyacrosstheInternetforalmosteverysingle A p I thatyouwillaccess, aswellasbrickandfigfilesandthingssuchasgamesintexteditorslikeGSCodeandmany, manyotherplacesthroughoutprogramming.
Also, almosteverysinglemajorlanguagehassomeformoflibraryorbuiltandfunctionalitytoparseJasonstringsintoobjectsorclassesinthatlanguage, whichmakesworkingwithJasondataextremelyeasyinsideof a programminglanguage.
Throughoutyourprogrammingcareer, you'regoingtouseJaceonallthetime, whetherit's creatinganAP, I consumingan A P I orcreatingCONFIGfilesforyoutoyoutorforotherpeopletouseforyourapplication.
NowthatweunderstandwhatJasonisandwhyit's important, Let's diveintosomeofthisintaxinvolved a JasonbystartingbytalkingaboutthetypesthatJasoncouldrepresent.
Asweknow, Jasonis a datarepresentationformat, soweneedtobuildtorepresent a certaindatatypeswithinitandJasonNativelysupportstringsnumbers, andthesenumberscouldbeinanyformat, whetherthey'redecimalnumbers, wholenumbers, negativenumbers, evenscientificnotationnumbers.
Soit's takenexampleof a userobjectthatwewanttoputatthetoplevelofourJaceonfile, whichwe'regoingtocalluserdotJasontocreateanobjectweneedtouseopeningandclosingcurlybraces.
Thekeymustbesurroundedbydoublequote, followedby a colonandthenthevalueforthatkey.
Andthen, ifwehavemultiplekeyvaluepairs, weneedcommasseparatingeverysingleoneofourkeyvaluepairssimilarlytohowwewouldcreateanarrayin a normalprogramminglanguage.
So, forexample, ifouruserhas a namewhichsurroundthatname, keyanddoublequotes, put a semicolonafter.
Andthentheendofthat, we'llput a commabecausewehaveotherkeyvaluepairsfor a user.
Forexample, ifwewantedtouse a favoritenumberasanotherproperty, we'llputfavoritenumberindoublequotes, followedby a semicolon, andthenputthatusersfavoritenumber.
Then, ifwewantedtouse a Boolean, weuse a commaandthenanotherproperty.
WewouldusehisprogrammerasArchyput a colon, andthenwehadputeithertrueorfalsewithnoquotesaroundit, tosignifythatthisis a Booleanandnot a string.
Soweputtrueorfalse, dependingonifthatuserwas a programmerornot, wecouldthengodownandusehobbiesasournextdevaluepair.
Andthat's howyoureallygetintothepowerofJason, whereyoucanstarttodeeplynestdifferentpropertiesandreallyshow a hierarchyofdataasopposedtojust a flatformoutofdata, likemostdataformatfilesgiveyou.
So, forexample, forthisfriendsofRay, wecouldhave a friendsofrage, anditcouldhavethesamepropertiesofnamefavoritenumberisprogrammerhobbiesandevenfriendsinsideofthat, andyoucanstarttoget a verydeeplymesseditovergray.
Ifyoureallywanted, thenwejusthavetomakesurethatwedon't put a commaontheverylastpropertyvalue.
Keepairthatwehavecloseitwith a curlybrace.
Andthat's ourfullJasonfilecreated.
NowthatweunderstandwhatJasonisandthisintaxinvolvedwithwritingJason, I'm goingtojumpinto a liveexampleofmewritingJasonfileandthenpartsinthatfileinJavaspares.
So I havevisualstudiocodeopenand I'm insideof a filecalledcosdotJason.
We'regoingtostoreanarrayofdifferentcompanies, andeachofthesecompaniesisgoingtohave a name, numberofemployees, a CEOandtheirratingoutoffive.
Solet's getstartedbyusingarsontextforcreating a ratewhichisusingopeningandclosingsquarebracketandinsideofthisarray, we'regoingtostoredifferentobjects.
Soourfirstobjectisgoingtobeourfirstcompany, which, aswementioned, has a nameandwe'rejustgoingtogivethatcompanynameofBigCorporation.
Nowherewehaveanothercompany, butmostofthetimewhenyou'redealingwithJason, they'regoingtogetitbackas a stringandnotasanactualjobscriptobject.
Sotoemulatethat, what's aroundthisandtactics.
Soit's anactualstring.
Andifyousaythatyouseethatnowourcouncil, itjusthas a stringinsteadofanactualobject, andwecanactuallyusethisobjectinsideofourjobiscurved.
Soinordertoconvertthis J somestringinto a JavaScriptobject, weneedtousewhat's calledjaysondotpartsSoifwegodowntoourlogandwesayJasondarkparsed, wepassitin a string, it'lltakethatstringandconvertitinto a Javascript.
Object.
Sonow, asyoucanseeinhere, wehaveourJavaScriptobjectthatwecreatedfromthisstringhere, usingjaysondotpartstoget a choiceonobjectrighthere.