Skip to content
Commits on Source (17)
*.cmi
*.cmo
*.cmx
*.cmxs
*.o
*.a
*.annot
*.cmt
*.cmti
META
basic.mli
out.html
read.ml
ydump
yojson.ml
yojson.mli
/_build/
/_opam/
.merlin
/*.install
PKG easy-format biniou
S .
B .
language: c
sudo: required
install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh
script: bash -ex .travis-opam.sh
env:
global:
- PACKAGE=yojson
matrix:
- OCAML_VERSION=4.02 OCAML_SWITCH=4.02.3
- OCAML_VERSION=4.03
- OCAML_VERSION=4.04
- OCAML_VERSION=4.05
- OCAML_VERSION=4.06
- OCAML_VERSION=4.07
os:
- linux
## 1.7.0
*2019-02-14*
### Add
- Add documented `write_t` and `read_t` to modules defining a JSON ast type for compatibility
with atdgen
## 1.6.0
*2019-01-30*
### Deprecate
- `json` types are deprecated in favor of their new `t` aliases, ahead of their removal in the next
major release (#73, @Leonidas-from-XIV)
### Add
- Add a type `t` and monomorphic `equal`, `pp` and `show` (#73, @Leonidas-from-XIV)
## 1.5.0
### Change
- Use dune as a build system (#67, @Leonidas-from-XIV)
- reraise exceptions in `finish_string` instead of silencing them by raising a `Failure _`
- raise finalizer exceptions in `from_channel` and `from_lexbuf` readers
### Fix
- Fix a race condition in builds (#57, @avsm)
# This file helps Github suggest reviewers of pull requests based on which
# files changed.
# Learn more at https://help.github.com/articles/about-codeowners/
# The lead maintainer(s)
* @NathanReb
Installation instructions for yojson
Requirements:
- Objective Caml (>= 3.11 is fine, earlier versions are probably fine too)
- GNU make
- Findlib (`ocamlfind' command)
- easy-format
- biniou
- cppo
GODI makes the installation process straightforward,
although other package managers can be equally convenient.
Manual installation is done using:
make # or `make all' for the bytecode-only version
make install # or `make BINDIR=/foo/bin install' for installing executables
# in a place other than the guessed default.
Uninstallation:
make uninstall
Bugs and feedback should be sent to Martin Jambon <martin@mjambon.com>.
name = "yojson"
version = "@@VERSION@@"
description = "JSON parsing and printing (successor of json-wheel)"
requires = "easy-format,biniou"
archive(byte) = "yojson.cmo"
archive(native) = "yojson.cmx"
archive(native,plugin) = "yojson.cmxs"
package "biniou" (
version = "@@VERSION@@"
description = "JSON <=> Biniou conversion"
requires = "easy-format,biniou"
archive(byte) = "yojson_biniou.cmo"
archive(native) = "yojson_biniou.cmx"
archive(native,plugin) = "yojson_biniou.cmxs"
)
# JBUILDER_GEN
package "biniou" (
description = "Deprecated. The yojson package already includes this"
requires = "yojson"
)
\ No newline at end of file
include $(shell ocamlc -where)/Makefile.config
.PHONY: all
all:
@dune build @install @examples
VERSION = 1.3.2
.PHONY: run-examples
run-examples:
dune exec examples/filtering.exe < examples/filtering.json
FLAGS = -bin-annot -dtypes -g
CMO = yojson.cmo yojson_biniou.cmo
CMX = yojson.cmx yojson_biniou.cmx
ifeq ($(NATDYNLINK),true)
CMXS = yojson.cmxs yojson_biniou.cmxs
endif
PACKS = easy-format,biniou
.PHONY: install
install:
@dune install
.PHONY: default all opt install uninstall install-lib uninstall-lib \
reinstall doc install-doc
default: META all opt
all: $(CMO)
opt: $(CMX) $(CMXS) ydump$(EXE)
.PHONY: uninstall
uninstall:
@dune uninstall
ifndef PREFIX
PREFIX = $(shell dirname $$(dirname $$(which ocamlfind)))
export PREFIX
endif
ifndef BINDIR
BINDIR = $(PREFIX)/bin
export BINDIR
endif
META: META.in Makefile
sed -e 's:@@VERSION@@:$(VERSION):' META.in > META
install: META install-lib
test ! -f ydump$(EXE) || cp ydump $(BINDIR)/
install-lib:
ocamlfind install yojson META \
$(wildcard *.cmt) $(wildcard *.cmti) $(wildcard *.mli) \
$(wildcard *.cmi) $(wildcard *$(EXT_LIB)) $(wildcard *.cmo) \
$(wildcard *$(EXT_OBJ)) $(wildcard *.cmx) $(wildcard *.cmxs)
uninstall: uninstall-lib
test ! -f $(BINDIR)/ydump$(EXE) || rm $(BINDIR)/ydump$(EXE)
uninstall-lib:
ocamlfind remove yojson
reinstall:
$(MAKE) BINDIR=$(BINDIR) uninstall
$(MAKE) BINDIR=$(BINDIR) install
read.ml: read.mll
ocamllex read.mll
yojson.mli: yojson.mli.cppo \
common.mli type.ml safe.mli write.mli pretty.mli write2.mli \
read.mli util.mli
cppo -n yojson.mli.cppo -o yojson.mli
yojson.ml: yojson.ml.cppo \
common.ml type.ml safe.ml write.ml pretty.ml write2.ml \
read.ml util.ml
cppo -D "VERSION $(VERSION)" yojson.ml.cppo -o yojson.ml
yojson.cmi: yojson.mli
ocamlfind ocamlc -c $(FLAGS) -package $(PACKS) yojson.mli
yojson.cmo: yojson.cmi yojson.ml
ocamlfind ocamlc -c $(FLAGS) -package $(PACKS) yojson.ml
yojson.cmx: yojson.cmi yojson.ml
ocamlfind ocamlopt -c $(FLAGS) -package $(PACKS) yojson.ml
yojson.cmxs: yojson.cmx
ocamlfind ocamlopt -shared -linkall -I . -o yojson.cmxs yojson.cmx
yojson_biniou.cmi: yojson_biniou.mli
ocamlfind ocamlc -c $(FLAGS) -package $(PACKS) yojson_biniou.mli
yojson_biniou.cmo: yojson_biniou.cmi yojson_biniou.ml
ocamlfind ocamlc -c $(FLAGS) -package $(PACKS) yojson_biniou.ml
yojson_biniou.cmx: yojson_biniou.cmi yojson_biniou.ml
ocamlfind ocamlopt -c $(FLAGS) -package $(PACKS) yojson_biniou.ml
yojson_biniou.cmxs: yojson_biniou.cmx
ocamlfind ocamlopt -shared -linkall -I . -o yojson_biniou.cmxs \
yojson_biniou.cmx
ydump$(EXE): yojson.cmx yojson_biniou.cmx ydump.ml
ocamlfind ocamlopt -o ydump$(EXE) $(FLAGS) -package $(PACKS) -linkpkg \
$(CMX) ydump.ml
doc: doc/index.html
doc/index.html: yojson.mli yojson_biniou.mli
mkdir -p doc
ocamlfind ocamldoc -d doc -html -package biniou \
yojson.mli yojson_biniou.mli
install-doc:
cp doc/* $$WWW/yojson-doc/
bench: bench.ml yojson.cmx META
ocamlfind ocamlopt -o bench \
-package unix,yojson,json-wheel -linkpkg bench.ml
.PHONY: bench
bench:
@dune build @bench --force
.PHONY: clean
clean:
rm -f *.o *.a *.cm* *~ *.annot ydump$(EXE) \
read.ml yojson.mli yojson.ml META
rm -rf doc
cd examples; $(MAKE) clean
@dune clean
.PHONY: test
test:
@dune runtest --force
Yojson: JSON library for OCaml
==============================
Yojson: low-level JSON library for OCaml
========================================
The main project page is http://mjambon.com/yojson.html
Yojson supersedes json-wheel.
[![Build Status](https://travis-ci.org/ocaml-community/yojson.svg?branch=master)](https://travis-ci.org/ocaml-community/yojson)
_This library is for manipulating the json AST directly. For mapping between OCaml types and json, we recommend [atdgen](https://github.com/mjambon/atd)._
Library documentation
---------------------
Currently at https://ocaml-community.github.io/yojson/
Design goals
------------
......@@ -22,8 +28,8 @@ Design goals
* providing a few non-standard, optional extensions of JSON.
These extensions will include:
* optional quotes around "simple" field/constructor names
* a syntax for tuples (at least 2 elements): (x, y)
* a syntax for variants (0 or 1 arg only): <Foo> <Bar:"abc">
* a syntax for tuples (at least 2 elements): `(x, y)`
* a syntax for variants (0 or 1 arg only): `<Foo> <Bar:"abc">`
Other choices already in json-wheel
......@@ -35,7 +41,7 @@ Other choices already in json-wheel
exchanging binary data:
* encoding is ASCII except for the contents of string literals
* string literals may represent arbitrary sequence of bytes
* \uABCD escapes in string literals expand to UTF-8
* `\uABCD` escapes in string literals expand to UTF-8
Miscellaneous
......
open Printf
let data =
let l = ref [] in
try
while true do
l := input_line stdin :: !l
done;
assert false
with End_of_file -> String.concat "\n" (List.rev !l)
let yojson_data = Yojson.Safe.from_string data
let jsonwheel_data = Json_io.json_of_string data
let n = 10_000
let yojson_rd_loop () =
for i = 1 to n do
ignore (Yojson.Safe.from_string data)
done
let yojson_wr_loop () =
for i = 1 to n do
ignore (Yojson.Safe.to_string yojson_data)
done
let jsonwheel_rd_loop () =
for i = 1 to n do
ignore (Json_io.json_of_string data)
done
let jsonwheel_wr_loop () =
for i = 1 to n do
ignore (Json_io.string_of_json ~compact:true jsonwheel_data)
done
let time msg f =
let t1 = Unix.gettimeofday () in
f ();
let t2 = Unix.gettimeofday () in
printf "%s: %.3f\n%!" msg (t2 -. t1)
let () =
time "rd yojson" yojson_rd_loop;
time "rd json-wheel" jsonwheel_rd_loop;
time "rd yojson" yojson_rd_loop;
time "rd json-wheel" jsonwheel_rd_loop;
time "wr yojson" yojson_wr_loop;
time "wr json-wheel" jsonwheel_wr_loop;
time "wr yojson" yojson_wr_loop;
time "wr json-wheel" jsonwheel_wr_loop
Benchmark for Yojson
====================
These benchmarks require `Core_bench` which is not a dependency of Yojson,
because it is not part of the regular installation/testing flow. This is solely
meant for developers that are worried about performance changes in Yojson.
This is also why it is deemed appropriate to depend on a benchmarking library
with this many dependencies: we rather spend time writing benchmarks than to
build a benchmarking library if a perfectly good one already exists in OCaml.
Install
-------
`opam install core_benchmark`
Running the benchmark
---------------------
`make bench` in the top level directory.
open Core
open Core_bench
let data =
In_channel.read_all "bench.json"
let yojson_data = Yojson.Safe.from_string data
(* chosen by fair dice roll, guaranteed to be large *)
let large = 10_000
let large_int_assoc =
let ints = List.init large (fun n ->
(string_of_int n, `Int n))
in
`Assoc ints
let large_int_list =
let ints = List.init large (fun n -> `Int n) in
`List ints
let large_string_list =
let strings = List.init large (fun n ->
`String (string_of_int n))
in
`List strings
let main () =
Command.run (Bench.make_command [
Bench.Test.create ~name:"JSON reading" (fun () ->
ignore (Yojson.Safe.from_string data));
Bench.Test.create ~name:"JSON writing" (fun () ->
ignore (Yojson.Safe.to_string yojson_data));
Bench.Test.create ~name:"JSON writing assoc" (fun () ->
ignore (Yojson.Safe.to_string large_int_assoc));
Bench.Test.create ~name:"JSON writing int list" (fun () ->
ignore (Yojson.Safe.to_string large_int_list));
Bench.Test.create ~name:"JSON writing string list" (fun () ->
ignore (Yojson.Safe.to_string large_string_list));
])
let () =
main ()
(executable
(name bench)
(flags (-safe-string))
(libraries yojson core_bench core))
(alias
(name bench)
(deps bench.json)
(action (run ./bench.exe)))
(executable
(name ydump)
(public_name ydump)
(flags (-safe-string))
(libraries yojson))
yojson (1.7.0-1) UNRELEASED; urgency=medium
* New upstream release
* Update Homepage and debian/watch
* Bump debhelper compat level to 12
* Bump Standards-Version to 4.4.0
* Remove Hendrik from Uploaders
* Update Vcs-*
-- Stéphane Glondu <glondu@debian.org> Mon, 12 Aug 2019 10:04:38 +0200
yojson (1.3.2-1) unstable; urgency=medium
* Team upload
......