diff options
| author | ilnurkh <[email protected]> | 2023-07-27 13:41:56 +0300 |
|---|---|---|
| committer | ilnurkh <[email protected]> | 2023-07-27 13:41:56 +0300 |
| commit | 1761cf17008788a7ec126e953ffe46c41721d168 (patch) | |
| tree | decb73843d5195cce15a243badf6614f1bf04909 /library/cpp/yson/node/node_io.cpp | |
| parent | 114da2ea902184524cac007509fbe899d8154b05 (diff) | |
add TryNodeFromJsonString: ability to parse object and check errors without try-catch
Diffstat (limited to 'library/cpp/yson/node/node_io.cpp')
| -rw-r--r-- | library/cpp/yson/node/node_io.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/library/cpp/yson/node/node_io.cpp b/library/cpp/yson/node/node_io.cpp index 294a7f7217f..26b95ef996d 100644 --- a/library/cpp/yson/node/node_io.cpp +++ b/library/cpp/yson/node/node_io.cpp @@ -126,6 +126,17 @@ void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, NYson:: visitor.Visit(node); } +bool TryNodeFromJsonString(const TStringBuf input, TNode& dst) +{ + TMemoryInput stream(input); + TNodeBuilder builder(&dst); + TYson2JsonCallbacksAdapter callbacks(&builder, /*throwException*/ false); + NJson::TJsonReaderConfig config; + config.DontValidateUtf8 = true; + NJson::ReadJson(&stream, &config, &callbacks); + return !callbacks.GetHaveErrors(); +} + TNode NodeFromJsonString(const TStringBuf input) { TMemoryInput stream(input); |
