{"id":965,"date":"2021-03-22T17:51:10","date_gmt":"2021-03-22T21:51:10","guid":{"rendered":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/?p=965"},"modified":"2021-03-22T17:51:21","modified_gmt":"2021-03-22T21:51:21","slug":"json","status":"publish","type":"post","link":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/topics\/javascript\/json\/","title":{"rendered":"JSON"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">WHAT<\/h2>\n\n\n\n<p>Short for JavaScript Object Notation it is a data file for JavaScript programming that allows for data to be saved and exchanged. It&#8217;s written in plain text so you can read it with any program that lets you read text files. You can create JSON files to store and use data in your own project and other sites make their data available through the JSON format.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Format<\/h2>\n\n\n\n<p>The json Format is essentially a JavaScript Object that contains a collection of name\/value pairs (also called key\/value). Here is an example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n   \"course\": \"MMP 350\",\n   \"year\": 2021\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Values<\/h3>\n\n\n\n<p>The values can be any one of these types:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>a string in double quotes: <strong>&#8220;my string&#8221;<\/strong><\/li><li>a number: <strong>2021<\/strong><\/li><li>boolean: <strong>true<\/strong> or <strong>false<\/strong><\/li><li>null: <strong>null<\/strong><\/li><li>an object: <strong>{ &#8220;name&#8221;: &#8220;value&#8221;}<\/strong><\/li><li>an array: <strong>[ &#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;]<\/strong><\/li><\/ol>\n\n\n\n<p>Here is an example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n   \"myString\": \"A string value\",\n   \"myNumber\": 2021,\n   \"myBoolean\": true,\n   \"myNull\": null,\n   \"myObject\": {\n                 \"name\":\"value\",\n                 \"id\":12345\n               },\n   \"myArray\":  &#91; \"a\", \"b\", \"c\"]\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Data from Other Sites<\/h2>\n\n\n\n<p>When other sites make their data available they usually do it in one of two ways:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Download: you download the file from their site, then save it with your site files and use it that way<\/li><li>API: they have created an API which allows you to get the data on the fly through JavaScript code.<\/li><\/ol>\n\n\n\n<p>An example of the first type would be going to this page: <a href=\"https:\/\/data.cityofnewyork.us\/Recreation\/Directory-of-Basketball-Courts\/b937-zdky\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/data.cityofnewyork.us\/Recreation\/Directory-of-Basketball-Courts\/b937-zdky<\/a><\/p>\n\n\n\n<p>and downloading a .json file of all of the basketball courts in NYC.<\/p>\n\n\n\n<p>An example of an API would be using the API described here: <a href=\"https:\/\/data.cityofnewyork.us\/Health\/Popular-Baby-Names\/25th-nujf\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/dev.socrata.com\/foundry\/data.cityofnewyork.us\/25th-nujf<\/a><\/p>\n\n\n\n<p>to dynamically load popular NYC baby names into a page. When you use an API you need to write code to load the data. This can by done through vanilla JavaScript or through a framework like jQuery.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sort and Filter<\/h3>\n\n\n\n<p>When using an API you can sort and filter the data you return. For example this URL <a rel=\"noreferrer noopener\" href=\"https:\/\/data.cityofnewyork.us\/resource\/25th-nujf.json?&amp;ethcty=HISPANIC&amp;gndr=FEMALE&amp;rnk=1\" target=\"_blank\">https:\/\/data.cityofnewyork.us\/resource\/25th-nujf.json?&amp;ethcty=HISPANIC&amp;gndr=FEMALE&amp;rnk=1<\/a> will give you just the top-ranked female Hispanic names for each year available.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WHAT Short for JavaScript Object Notation it is a data file for JavaScript programming that allows for data to be saved and exchanged. It&#8217;s written in plain text so you can read it with any program that lets you read text files. You can create JSON files to store and use data in your own&hellip; <a class=\"more-link\" href=\"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/topics\/javascript\/json\/\">Continue reading <span class=\"screen-reader-text\">JSON<\/span><\/a><\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","portfolio_post_id":0,"portfolio_citation":"","portfolio_annotation":"","openlab_post_visibility":"","footnotes":""},"categories":[20],"tags":[],"coauthors":[],"class_list":["post-965","post","type-post","status-publish","format-standard","hentry","category-javascript","entry"],"featured_image_urls_v2":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":"","post-thumbnail":"","gform-image-choice-sm":"","gform-image-choice-md":"","gform-image-choice-lg":""},"post_excerpt_stackable_v2":"<p>WHAT Short for JavaScript Object Notation it is a data file for JavaScript programming that allows for data to be saved and exchanged. It&#8217;s written in plain text so you can read it with any program that lets you read text files. You can create JSON files to store and use data in your own project and other sites make their data available through the JSON format. Format The json Format is essentially a JavaScript Object that contains a collection of name\/value pairs (also called key\/value). Here is an example { &#8220;course&#8221;: &#8220;MMP 350&#8221;, &#8220;year&#8221;: 2021 } Values The values&hellip;<\/p>\n","category_list_v2":"<a href=\"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/category\/topics\/javascript\/\" rel=\"category tag\">JavaScript<\/a>","author_info_v2":{"name":"Christopher Stein","url":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/author\/cstein\/"},"comments_num_v2":"1 comment","uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false,"gform-image-choice-sm":false,"gform-image-choice-md":false,"gform-image-choice-lg":false},"uagb_author_info":{"display_name":"Christopher Stein","author_link":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/author\/cstein\/"},"uagb_comment_info":1,"uagb_excerpt":"WHAT Short for JavaScript Object Notation it is a data file for JavaScript programming that allows for data to be saved and exchanged. It&#8217;s written in plain text so you can read it with any program that lets you read text files. You can create JSON files to store and use data in your own&hellip;&hellip;","_links":{"self":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/posts\/965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/comments?post=965"}],"version-history":[{"count":3,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/posts\/965\/revisions"}],"predecessor-version":[{"id":968,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/posts\/965\/revisions\/968"}],"wp:attachment":[{"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/media?parent=965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/categories?post=965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/tags?post=965"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/openlab.bmcc.cuny.edu\/mmp-350-spring-21\/wp-json\/wp\/v2\/coauthors?post=965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}