JSON. Version 6.6. Eli Barzilay and Dave Herman. July 22, 2016

Similar documents
Programming Languages: Application and Interpretation

Syntax: Meta-Programming Helpers

Syntax Color: Utilities

Readline: Terminal Interaction

XML: Parsing and Writing

Typescript on LLVM Language Reference Manual

Introduction to Programming Using Java (98-388)

Readline: Terminal Interaction

Programming Languages: Application and Interpretation

Browser: Simple HTML Rendering

Essentials of Programming Languages Language

Flat triples approach to RDF graphs in JSON

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Racket: Modules, Contracts, Languages

Internet Engineering Task Force (IETF) Obsoletes: 4627, 7158 March 2014 Category: Standards Track ISSN:

Project 2: Scheme Interpreter

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples

Avro Specification

2D Syntax. Version October 30, 2017

Binghamton University. CS-140 Fall Data Types in Java

Net: Networking Libraries

ECMA-404. The JSON Data Interchange Syntax. 2 nd Edition / December Reference number ECMA-123:2009

This tutorial will help you understand JSON and its use within various programming languages such as PHP, PERL, Python, Ruby, Java, etc.

Armide Documentation. Release Kyle Mayes

/chapter/1 In the beginning there was request?

XDS An Extensible Structure for Trustworthy Document Content Verification Simon Wiseman CTO Deep- Secure 3 rd June 2013

Avro Specification

Language Reference Manual simplicity

Honu. Version November 6, 2010

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Variables, Constants, and Data Types

LOON. Language Reference Manual THE LANGUAGE OF OBJECT NOTATION. Kyle Hughes, Jack Ricci, Chelci Houston-Borroughs, Niles Christensen, Habin Lee

Essentials of Programming Languages Language

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016

Typed Racket: Racket with Static Types

Modules, Structs, Hashes, and Operational Semantics

CSC Web Technologies, Spring Web Data Exchange Formats

CSCI312 Principles of Programming Languages!

FrTime: A Language for Reactive Programs

XML: Parsing and Writing

ECE570 Lecture 2: Types and Conventions

ECE473 Lecture 2: Types and Conventions

How to Design Programs Languages

Parser Tools: lex and yacc-style Parsing

Internet Engineering Task Force (IETF) Request for Comments: 8259 Obsoletes: 7159 December 2017 Category: Standards Track ISSN:

B.V. Patel Institute of BMC & IT, UTU 2014

Scheme Quick Reference

The Typed Racket Reference

Oli Language Documentation

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Princeton University. Computer Science 217: Introduction to Programming Systems. Data Types in C

QUark Language Reference Manual

How to Design Programs Languages

pybdg Documentation Release 1.0.dev2 Outernet Inc

LISP - SEQUENCES. The function make-sequence allows you to create a sequence of any type. The syntax for this function is:

The Typed Racket Guide

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Scheme Quick Reference

CSC 533: Programming Languages. Spring 2015

CIS192 Python Programming. Robert Rand. August 27, 2015

Implementing HtDP Teachpacks, Libraries, and Customized Teaching Languages

Modern Programming Languages. Lecture LISP Programming Language An Introduction

ECS 142 Spring Project (part 2): Lexical and Syntactic Analysis Due Date: April 22, 2011: 11:59 PM.

Functional Programming. Pure Functional Languages

How to Design Programs

Large Scheme: A Personal View

10/4/18. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntactic Analysis

LINK Mobility SMS REST API MO messages Version 1.1; Last updated June 07, 2017

Building lexical and syntactic analyzers. Chapter 3. Syntactic sugar causes cancer of the semicolon. A. Perlis. Chomsky Hierarchy

asn1tools Documentation

FrTime: A Language for Reactive Programs

The Object Model Overview. Contents. Section Title

JSON Support for Junos OS

CS 33. Introduction to C. Part 5. CS33 Intro to Computer Systems V 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Compiler Construction D7011E

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

Scheme: Expressions & Procedures

Syntax Intro and Overview. Syntax

Lisp: Lab Information. Donald F. Ross

Dynext: Running a C Compiler/Linker

SOAPScript For squeaky-clean code, use SOAPScript Language Summary Bob Nisco Version 0.5 β

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

Lisp. Versions of LISP

Project 1: Scheme Pretty-Printer

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

Programming Assignment II

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

GOLD Language Reference Manual

BDS Query. JSON Query Syntax

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

La Mesa Language Reference Manual COMS 4115: Programming Languages and Translators Professor Stephen Edwards

Chapter 14 Sequential Access Files

Module 3: New types of data


Language Reference Manual

Chapter 2: Using Data

The Warhol Language Reference Manual

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Transcription:

JSON Version 6.6 Eli Barzilay and Dave Herman July 22, 2016 (require json) package: base This library provides utilities for parsing and producing data in the JSON data exchange format to/from Racket values. See the JSON web site and the JSON RFC for more information about JSON. 1

1 JS-Expressions (jsexpr? x [#:null jsnull]) Ñ boolean? x : any Performs a deep check to determine whether x is a jsexpr. This library defines a subset of Racket values that can be represented as JSON strings, and this predicates checks for such values. A JS-Expression, or jsexpr, is one of: the value of jsnull, 'null by default boolean? string? (or exact-integer? inexact-real?) (listof jsexpr?) (hasheqof symbol? jsexpr?) (json-null) Ñ any? (json-null jsnull) Ñ void? jsnull : any? This parameter determines the default Racket value that corresponds to a JSON null. By default, it is the 'null symbol. In some cases a different value may better fit your needs, therefore all functions in this library accept a #:null keyword argument for the value that is used to represent a JSON null, and this argument defaults to (json-null). 2

2 Generating JSON Text from JS-Expressions (write-json x [out #:null jsnull #:encode encode]) Ñ any out : output-port? = (current-output-port) Writes the x jsexpr, encoded as JSON, to the outp output port. By default, only ASCII control characters are encoded as \uhhhh. If encode is given as 'all, then in addition to ASCII control characters, non-ascii characters are encoded as well. This can be useful if you need to transport the text via channels that might not support UTF-8. Note that characters in the range of U+10000 and above are encoded as two \uhhhh escapes, see Section 2.5 of the JSON RFC. (jsexpr->string x [#:null jsnull #:encode encode]) Ñ string? Generates a JSON source string for the jsexpr x. (jsexpr->bytes x [#:null jsnull #:encode encode]) Ñ bytes? Generates a JSON source byte string for the jsexpr x. (The byte string is encoded in UTF-8.) 3

3 Parsing JSON Text into JS-Expressions (read-json [in #:null jsnull]) Ñ (or/c jsexpr? eof-object?) in : input-port? = (current-input-port) Reads a jsexpr from a JSON-encoded input port in as a Racket (immutable) value, or produces eof if only whitespace remains. (string->jsexpr str [#:null jsnull]) Ñ jsexpr? str : string? Parses the JSON string str as an immutable jsexpr. (bytes->jsexpr str [#:null jsnull]) Ñ jsexpr? str : bytes? Parses the JSON bytes string str as an immutable jsexpr. 4

4 A Word About Design 4.1 The JS-Expression Data Type JSON syntactically distinguishes null, array literals, and object literals, and therefore there is a question of what Racket value should represent a JSON null. This library uses the Racket 'null symbol by default. Note that this is unambiguous, since Racket symbols are used only as object keys, which are required to be strings in JSON. Several other options have been used by various libaries. For example, Dave Herman s PLaneT library (which has been the basis for this library) uses the #\nul character, other libraries for Racket and other Lisps use (void), NIL (some use it also for JSON false ), and more. The approach taken by this library is to use a keyword argument for all functions, with a parameter that determines its default, making it easy to use any value that fits your needs. The JSON RFC only states that object literal expressions SHOULD contain unique keys, but does not proscribe them entirely. Looking at existing practice, it appears that popular JSON libraries parse object literals with duplicate keys by simply picking one of the keyvalue pairs and discarding the others with the same key. This behavior is naturally paralleled by Racket hash tables, making them a natural analog. Finally, the JSON RFC is almost completely silent about the order of key-value pairs. While the RFC only specifies the syntax of JSON, which of course always must represent object literals as an ordered collection, the introduction states: An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array. In practice, JSON libraries discard the order of object literals in parsed JSON text and make no guarantees about the order of generated object literals, usually using a hash table of some flavor as a natural choice. We therefore use do so as well. 4.2 Naming Conventions Some names in this library use jsexpr and some use json. The rationale that the first is used for our representation, and the second is used as information that is received from or sent to the outside world. 5