Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
asdf.jsonparser
Json Parser
Authors:
Ilya Yaroshenko
License:
MIT
Parses json value
Parameters:
Chunks chunks | input range composed of elements type of const(ubyte)[]. chunks can use the same buffer for each chunk. |
size_t initLength | initial output buffer length. Minimal value equals 32. |
Returns:
ASDF value
Examples:
import std.range: chunks; auto text = cast(const ubyte[])`true `; auto ch = text.chunks(3); assert(ch.parseJson(32).data == [1]);
Asdf parseJson(Flag!"includingNewLine" includingNewLine = Yes.includingNewLine, Flag!"spaces" spaces = Yes.spaces, Flag!"assumeValid" assumeValid = No.assumeValid, Allocator)(in char[] str, Allocator allocator);
Asdf parseJson(Flag!"includingNewLine" includingNewLine = Yes.includingNewLine, Flag!"spaces" spaces = Yes.spaces, Flag!"assumeValid" assumeValid = No.assumeValid)(in char[] str);
Asdf parseJson(Flag!"includingNewLine" includingNewLine = Yes.includingNewLine, Flag!"spaces" spaces = Yes.spaces, Flag!"assumeValid" assumeValid = No.assumeValid)(in char[] str);
Parses json value
Parameters:
char[] str | input string |
Allocator allocator | (optional) memory allocator |
Returns:
ASDF value
Examples:
assert(`{"ak": {"sub": "subval"} }`.parseJson["ak", "sub"] == "subval");
Parses JSON value in each line from a Range of buffers.
Parameters:
spaces | adds support for spaces beetwen json tokens. Default value is Yes. |
throwOnInvalidLines | throws an AsdfException on invalid lines if Yes and ignore invalid lines if No. Default value is No. |
Input input | input range composed of elements type of const(ubyte)[] or string / const(char)[]. chunks can use the same buffer for each chunk. |
Returns:
Input range composed of ASDF values. Each value uses the same internal buffer.
Examples:
import asdf.jsonparser; import std.range: chunks; auto text = cast(const ubyte[])"\t true \r\r\n false\t"; auto values = text.chunks(3).parseJsonByLine; assert(values.front.data == [1]); values.popFront; assert(values.front.data == [2]); values.popFront; assert(values.empty);
Examples:
import std.conv; import std.algorithm : map; import std.range : array; string text = "\t " ~ `{"key": "a"}` ~ "\r\r\n" ~ `{"key2": "b"}`; auto values = text.parseJsonByLine(); assert( values.front["key"] == "a"); values.popFront; assert( values.front["key2"] == "b"); values.popFront;
Tamedia Digital, 2016-2017
| Page generated by
Ddoc on Sat Apr 7 16:50:38 2018