libexpr/json-to-value: Migrate parseJSON to return a Value

Part of #1136

Change-Id: I5ac23ce461a106360b150e64a6bc0f2f6a6a6964
This commit is contained in:
skye
2026-04-07 22:37:44 -04:00
parent bb9f9cf553
commit 658404c2a0
3 changed files with 4 additions and 5 deletions
+2 -2
View File
@@ -190,13 +190,13 @@ public:
}
};
void parseJSON(EvalState & state, const std::string_view & s_, Value & v)
Value parseJSON(EvalState & state, const std::string_view & s_)
{
JSONSax parser(state);
bool res = JSON::sax_parse(s_, &parser);
if (!res)
throw JSONParseError("Invalid JSON Value");
v = parser.result();
return parser.result();
}
}
+1 -2
View File
@@ -12,6 +12,5 @@ struct Value;
MakeError(JSONParseError, Error);
void parseJSON(EvalState & state, const std::string_view & s, Value & v);
Value parseJSON(EvalState & state, const std::string_view & s);
}
+1 -1
View File
@@ -1622,7 +1622,7 @@ static void prim_fromJSON(EvalState & state, Value * * args, Value & v)
{
auto s = state.forceStringNoCtx(*args[0], noPos, "while evaluating the first argument passed to builtins.fromJSON");
try {
parseJSON(state, s, v);
v = parseJSON(state, s);
} catch (JSONParseError &e) {
e.addTrace(nullptr, "while decoding a JSON string");
throw;