Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 8 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,23 @@
# JSON

Opendylan library to parse the JSON standard file format.
A library to parse the JSON standard file format.

## Install

Add `json` to your project dependencies
Add `json` to your project dependencies in `dylan-package.json`:

```json
"dependencies": [ "json" ],
```

Update the dependencies:
Update your workspace with the new dependencies:

```
dylan update
deft update
```

## Usage
## Documentation

Add `use json;` in the library and module section of your
`library.dylan` file.

This library exports the following methods:

- `parse-json` and
- `print-json`

### Parse JSON

An example of usage of `parse-json`:

```dylan
let json = """
{
"a": 1,
"b": 2
}
""";

let json-table = parse-json(json);
format-out("a = %d", json-table["a"]);
```

[Run this code](https://play.opendylan.org/shared/d123253033bda66a) in
https://play.opendylan.org

### Print JSON

`print-json` is used to pretty print a `table` in JSON format,
following the previous example:

```dylan
print-json(json-table, *standard-output*, indent: 2);
```

[Run a complete example](https://play.opendylan.org/shared/06af84b39fab129b) in
https://play.opendylan.org
Documentation is available in the [Dylan package
docs](https://package.opendylan.org/json/index.html) or it may be read in source form in
`documentation/source/index.rst`.
29 changes: 17 additions & 12 deletions documentation/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,16 @@ Parsing

.. code-block:: dylan

let data = """{"a": 1, "b": 2,}""";
let parsed = parse-json(data, strict?: #f);
let a = parsed["a"];
let data = """
{
"a": 1,
"b": 2,
}
""";
let parsed = parse-json(data, strict?: #f);
format-out("%=, %=", parsed["a"], parsed["b"]);

`Run this example <https://play.opendylan.org/shared/89037b0be1300a55>`_
in https://play.opendylan.org
`Run this example <https://play.opendylan.org/shared/611eee83bba6d65f>`_

Note the use of ``strict?: #f`` is needed since *data* has a
trailing comma after the number 2.
Expand All @@ -115,14 +119,15 @@ Parsing

.. code-block:: dylan

with-open-file (fs = "data.json")
let data = parse-json(fs, strict?: #f);
...
end;
let input = """
{ "x": 123 }
""";
with-input-from-string (stream = input)
let json = parse-json(stream, strict?: #f);
format-out("x is %d", json["x"]);
end;

`Run an example
<https://play.opendylan.org/shared/24c4ac32aaf6a5b5>`_ with a
string stream in https://play.opendylan.org
`Run this example <https://play.opendylan.org/shared/1817e54146dacc16>`_


Printing
Expand Down
1 change: 0 additions & 1 deletion registry/generic/json

This file was deleted.

1 change: 0 additions & 1 deletion registry/generic/json-test-suite

This file was deleted.

Loading