Skip to content
/ json Public

JSON parser and converter for the Stanza programming language

License

Notifications You must be signed in to change notification settings

dwnusbaum/json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json

JSON parser and converter for the Stanza programming language.

Installation

git clone https://github.com/dwnusbaum/json.git <path>
<path>/compile.sh <desired-package-path>

Overview

To use the library, add import json to your stanza imports. When compiling your code, use stanza <infiles> -o <outfile> -pkg-path <desired-package-path>

Example

defpackage test-package:
    import core
    import collections
    import json

    val json-string:String = "{\"name\":\"test\"}"

    val parsed-value = from-json(json-string)

    match(parsed-value):
        (object:HashTable<String,?>):
            for entry in object do:
                println $ entry
        (error):
            println $ error

Library Functions

  • from-json (:String) -> HashTable<String,?>|Vector<?>|Int|Double|String|False|True|None: Parses a JSON string into a stanza value.
  • from-json-file (filename:String) -> HashTable<String,?>|Vector<?>|Int|Double|String|False|True|None: Parses a JSON file into a stanza value. Loads the whole file into memory at once.
  • to-json (stanza-value) -> String: Turns a stanza value into a json string, without newlines or spaces.
  • to-json (stanza-value, pretty:False|True) -> String: Turns a stanza value into a json string, with newlines and 4 space indentation if pretty is true.
  • to-json (stanza-value, pretty:False|True, indent-size:Int) -> String: Turns a stanza value into a json string, with newlines and indent-size space indentation if pretty is true.

Known Limitations

  • Currently, incremental file parsing is not supported. To add it, the FileInputStream type would need to be augmented to include a peek? function, like the StringInputStream type.
  • Stanza does not seem to support unicode yet, so all unicode characters will be truncated to single byte ASCII characters.

###Tests

To run the test suite:

./compile.sh && ./test.sh

About

JSON parser and converter for the Stanza programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages