json

Checks if a JSON value contains another JSON value. Keys that are only in the first JSON value are ignored.

In other words, every value in the second JSON value must appear in the same position in the first value.

This satisfies the JSON convention that extraneous keys are ignored.

  1. void json(Should should, JSONValue expected, Fence _, string file, size_t line)
  2. void json(Should should, Fence _, string file, size_t line)
    void
    json
    (
    string jsonString
    Should
    )
    (
    Should should
    ,
    Fence _ = Fence()
    ,
    string file = __FILE__
    ,
    size_t line = __LINE__
    )
    if (
    isInstanceOf!(ShouldType, Should)
    )

Examples

import dshould : be;

`{"a": 5, "b": 6}`.parseJSON.should.be.json!`{"a": 5, "b": 6}`;
`{"a": 5, "b": 6}`.parseJSON.should.be.json!`{"b": 6, "a": 5}`;
`{"a": 5, "b": 6}`.parseJSON.should.be.json!`{"a": 5}`.should.throwAn!Error;
`{"a": 5, "b": 6}`.parseJSON.should.contain.json!`{"a": 5}`;
import dshould : be;

`{"a": 5, "b": 6}`.parseJSON.should.be.json(`{"a": 5, "b": 6}`.parseJSON);
`{"a": 5, "b": 6}`.parseJSON.should.be.json(`{"b": 6, "a": 5}`.parseJSON);
`{"a": 5, "b": 6}`.parseJSON.should.be.json(`{"a": 5}`.parseJSON).should.throwAn!Error;
`{"a": 5, "b": 6}`.parseJSON.should.contain.json(`{}`.parseJSON);
`{"a": 5, "b": 6}`.parseJSON.should.contain.json(`{"b": 6}`.parseJSON);
`{"a": 5, "b": 6}`.parseJSON.should.contain.json(`{"c": 4}`.parseJSON).should.throwAn!Error;

`{"x": {"a": 5, "b": 6}}`.parseJSON.should.contain.json(`{"x": {"b": 6}}`.parseJSON);
`{"x": {"a": 5, "b": 6}}`.parseJSON.should.contain.json(`{"x": {"c": 4}}`.parseJSON).should.throwAn!Error;

`{"a": 5, "b": 6}`.parseJSON.should.contain.json(`{"b": 5}`.parseJSON).should.throwAn!Error;

`[2, 3]`.parseJSON.should.contain.json(`[2, 3]`.parseJSON);
`[2, 3]`.parseJSON.should.contain.json(`[2]`.parseJSON).should.throwAn!Error;

Meta