Giter Site home page Giter Site logo

fp1's Introduction

Programmer: Tony Ventura

My Library: JSON

For FP1, I explored the JSON library. I was able to convert a JSON expression into a string, read a JSON expression from a file, print them both, and test for valid JSON expressions.

To start my program off I first defined a string str. The string was a simple example I discovered on stackexchange:

(define str "{\"foo\": \"bar\", \"bar\": \"baz\"}")

Afterwards, I used string->jsexpr which does exactly as it's written. Writing (string->jsexpr str) would convert a string into a JSON expression. I defined this to be x in my program.

(define x (string->jsexpr str))

With a JSON expression x, it was easy to use jsexpr->string to convert my x back into a string. I defined this as y:

(define y (jsexpr->string x))

I then was able to read in a sample JSON file from the internet. This file will be named "test.json" in this repo. read-json reads a JSON expression from a valid input port, which ended up being (open-input-file "test.json") I defined this input to be z:

(define z (read-json (open-input-file "test.json")))

Finally I played around with (jsexpr? x) to determine json expressions. As per the documentation for (jsexpr? x), the procedure will return true when x is:

  • the value of jsnull, 'null by default
  • boolean?
  • string?
  • (or exact-integer? inexact-real?)
  • (listof jsexpr?)
  • (hasheqof symbol? jsexpr?)

My x, y, and z would be valid jsexpr, as would 'null as I haven't changed jsnull's default value. I worked out (jsexpr? 2.7+3i) as a test case that should fail which worked in my tests.

(jsexpr? 'null)  ;; #t
(jsexpr? 2.7+3i) ;; #f
(jsexpr? x)      ;; #t
(jsexpr? y)      ;; #t
(jsexpr? z)      ;; #t

Below is the output of my program, with spaced between each test. alt-text

fp1's People

Contributors

marksherman avatar tventura1337 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.