in python/moz/l10n/message/from_json.py [0:0]
def message_from_json(json: list[Any] | dict[str, Any]) -> Message:
"""
Marshal the JSON output of `moz.l10n.message.to_json()`
back into a parsed `moz.l10n.message.data.Message`.
May raise `MF2ValidationError`.
"""
if isinstance(json, Mapping) and "sel" in json:
return SelectMessage(
declarations={
name: _expression_from_json(value)
for name, value in json["decl"].items()
},
selectors=tuple(VariableRef(sel) for sel in json["sel"]),
variants={
tuple(
key if isinstance(key, str) else CatchallKey(key["*"] or None)
for key in variant["keys"]
): _pattern_from_json(variant["pat"])
for variant in json["alt"]
},
)
else:
declarations = {}
if isinstance(json, Mapping):
if "decl" in json:
declarations = {
name: _expression_from_json(value)
for name, value in json["decl"].items()
}
pattern = _pattern_from_json(json["msg"])
else:
pattern = _pattern_from_json(json)
return PatternMessage(pattern, declarations)