A Calculus with Partially Dynamic Records for Typeful Manipulation of JSON Objects

Authors Atsushi Ohori, Katsuhiro Ueno, Tomohiro Sasaki, Daisuke Kikuchi



PDF
Thumbnail PDF

File

LIPIcs.ECOOP.2016.18.pdf
  • Filesize: 0.53 MB
  • 25 pages

Document Identifiers

Author Details

Atsushi Ohori
Katsuhiro Ueno
Tomohiro Sasaki
Daisuke Kikuchi

Cite AsGet BibTex

Atsushi Ohori, Katsuhiro Ueno, Tomohiro Sasaki, and Daisuke Kikuchi. A Calculus with Partially Dynamic Records for Typeful Manipulation of JSON Objects. In 30th European Conference on Object-Oriented Programming (ECOOP 2016). Leibniz International Proceedings in Informatics (LIPIcs), Volume 56, pp. 18:1-18:25, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2016)
https://doi.org/10.4230/LIPIcs.ECOOP.2016.18

Abstract

This paper investigates language constructs for high-level and type-safe manipulation of JSON objects in a typed functional language. A major obstacle in representing JSON in a static type system is their heterogeneous nature: in most practical JSON APIs, a JSON array is a heterogeneous list consisting of, for example, objects having common fields and possibly some optional fields. This paper presents a typed calculus that reconciles static typing constraints and heterogeneous JSON arrays based on the idea of partially dynamic records originally proposed and sketched by Buneman and Ohori for complex database object manipulation. Partially dynamic records are dynamically typed records, but some parts of their structures are statically known. This feature enables us to represent JSON objects as typed data structures. The proposed calculus smoothly extends with ML-style pattern matching and record polymorphism. These results yield a typed functional language where the programmer can directly import JSON data as terms having static types, and can manipulate them with the full benefits of static polymorphic type-checking. The proposed calculus has been embodied in SML#, an extension of Standard ML with record polymorphism and other practically useful features. This paper also reports on the details of the implementation and demonstrates its feasibility through examples using actual Web APIs. The SML# version 3.1.0 compiler includes JSON support presented in this paper, and is available from Tohoku University as open-source software under a BSD-style license.
Keywords
  • JSON
  • Type System
  • Polymorphic Record Calculus

Metrics

  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    0
    PDF Downloads

References

  1. M. Abadi and L. Cardelli. A Theory of Objects. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1996. Google Scholar
  2. M. Abadi, L. Cardelli, B. Pierce, and G. Plotkin. Dynamic typing in a statically-typed language. ACM Transcations on Programming Languages and Systems, 13(2):237-268, 1991. Google Scholar
  3. V. Benzaken, G. Castagna, and A. Frisch. CDuce: An XML-centric general-purpose language. In Proceedings of the ACM International Conference on Functional Programming, pages 51-63, 2003. Google Scholar
  4. G. Bierman, M. Abadi, and M. Torgersen. Understanding TypeScript. In Proceedings of the European conference on Object-Oriented Programming, pages 257-281. Springer Berlin Heidelberg, 2014. Google Scholar
  5. T. Bray. The JavaScript Object Notation (JSON) Data Interchange Format. RFC 7159 (Proposed Standard), 2014. URL: http://www.ietf.org/rfc/rfc7159.txt.
  6. P. Buneman and A. Ohori. Polymorphism and type inference in database programming. ACM Transactions on Database Systems, 21(1):30-74, 1996. Google Scholar
  7. D. Colazzo, G. Ghelli, and C. Sartiani. Typing massive JSON datasets. In Proceedings of the International Workshop on Cross-model Language Design and Implementation (XLDI), Copenhagen, Denmark, 2012. Google Scholar
  8. J. Dimino. Camlp4, 2014. URL: https://opam.ocaml.org/packages/camlp4/camlp4.4.03.0/.
  9. Flow | a static typechecker for JavaScript. URL: http://flowtype.org.
  10. A. Frisch. OCaml + XDuce. In Proceedings of the ACM International Conference on Functional Programming, pages 192-200, 2006. Google Scholar
  11. A. Frisch, G. Castagna, and V. Benzaken. Semantic subtyping: Dealing set-theoretically with function, union, intersection, and negation types. Journal of the ACM, 55(4), 2008. Google Scholar
  12. Google Maps APIs | Google Developers. URL: https://developers.google.com/maps/.
  13. D. Hardt. The OAuth 2.0 Authorization Framework. RFC 6749, 2012. URL: http://www.ietf.org/rfc/rfc6749.txt.
  14. H. Hosoya and B. Pierce. XDuce: A statically typed XML processing language. ACM Trans. Internet Technol., 3(2):117-148, 2003. Google Scholar
  15. M. Jambon. Atdgen, 2010. URL: https://github.com/mjambon/atdgen.
  16. M. Jambon. Yojson: JSON library for OCaml, 2010-2012. URL: https://github.com/mjambon/yojson.
  17. JSON schema. URL: http://json-schema.org.
  18. G. Kahn. Natural semantics. In Proceedings of the Symposium on Theoretical Aspects of Computer Science, pages 22-39. Springer Verlag, 1987. Google Scholar
  19. O. Kiselyov, R. Lämmel, and K. Schupke. Strongly typed heterogeneous collections. In Proceedings of the ACM SIGPLAN Workshop on Haskell, pages 96-107, 2004. Google Scholar
  20. A. Ohori. A polymorphic record calculus and its compilation. ACM Transactions on Programming Languages and Systems, 17(6):844-895, 1995. A preliminary summary appeared at ACM POPL, 1992 under the title "A compilation method for ML-style polymorphic record calculi.". Google Scholar
  21. A Ohori and K. Ueno. Making Standard ML a practical database programming language. In Proceedings of the ACM International Conference on Functional Programming, pages 307-319, 2011. Google Scholar
  22. A. Ohori, K. Ueno, K. Hoshi, S. Nozaki, T. Sato, T. Makabe, and Y. Ito. SML# in industry: A practical ERP system development. In Proceedings of the ACM International Conference on Functional Programming, pages 167-173, 2014. Google Scholar
  23. OpenWeatherMap.org. OpenWeatherMap, 2012-2016. URL: http://openweathermap.org.
  24. B. O'Sullivan. Aeson: Fast JSON parsing and encoding, 2011-2014. URL: https://hackage.haskell.org/package/aeson.
  25. J. Siek and W. Taha. Gradual typing for objects. In Proceedings of the European conference on Object-Oriented Programming, pages 2-27, 2007. Google Scholar
  26. SML#, 2006-2016. URL: http://www.riec.tohoku.ac.jp/smlsharp/.
  27. D. Syme, K. Battocchi, K. Takeda, D. Malayeri, J. Fisher, J. Hu, T. Liu, B. McNamara, D. Quirk, M. Taveggia, W. Chae, U. Matsveyeu, and T. Petricek. F#3.0 - strongly-typed language support for internet-scale information sources. Technical Report MSR-TR-2012-101, Microsoft Research, 2012. Google Scholar
  28. The Search API | Twitter Developers. URL: https://dev.twitter.com/rest/public/search.
Questions / Remarks / Feedback
X

Feedback for Dagstuhl Publishing


Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail