项目作者: tomooda

项目描述 :
JSON parser/printer for VDM-SL
高级语言:
项目地址: git://github.com/tomooda/JSONUtil.git
创建时间: 2013-12-18T23:53:57Z
项目社区:https://github.com/tomooda/JSONUtil

开源协议:MIT License

下载


JSONUtil

JSON parser/printer for VDM-SL

CAUTION : JSONUtil does NOT distinguish “” and [] because neither does VDM-SL.

JSON <-> VDM mappings

  1. JSON = seq of char;
  2. STRING = seq of char;
  3. ARRAY = seq of VALUE;
  4. OBJECT = map STRING to VALUE;
  5. NUMBER = real;
  6. BOOL = bool;
  7. VALUE = [ STRING | ARRAY | OBJECT | NUMBER | BOOL ];

exports the following functions

parseJSON : JSON -> bool * VALUE;

parses the given JSON string into a VDM value. This function permits extra data after a valid JSON portion.

  1. parseJSON("[1, true, \"string\", {\"key\":\"value\"}]")
  2. ==> mk_(true, [1, true, "string", {"key" |-> "value"}])
  3. parseJSON("[1, true, \"string\", {\"key\":\"value\"}] EXTRA")
  4. ==> mk_(true, [1, true, "string", {"key" |-> "value"}])

strictParseJSON : JSON -> bool * VALUE;

parses the given JSON string into a VDM value. This function does NOT permit extra data after a valid JSON portion.

  1. strictParseJSON("[1, true, \"string\", {\"key\":\"value\"}]")
  2. ==> mk_(true, [1, true, "string", {"key" |-> "value"}])
  3. strictParseJSON("[1, true, \"string\", {\"key\":\"value\"}] EXTRA")
  4. ==> mk_(false, nil)

printJSON : VALUE -> JSON;

prints the VALUE values into JSON format.

  1. printJSON([1, true, "string", {"key" |-> "value"}])
  2. ==> "[1, true, \"string\", {\"key\":\"value\"}]"