跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

jsondecode Function ​

jsondecode interprets a given string as JSON, returning a representation of the result of decoding that string.

The JSON encoding is defined in RFC 7159.

This function maps JSON values to Packer language values in the following way:

JSON typePacker type
Stringstring
Numbernumber
Booleanbool
Objectobject(...) with attribute types determined per this table
Arraytuple(...) with element types determined per this table
NullThe Packer language null value

The Packer language automatic type conversion rules mean that you don't usually need to worry about exactly what type is produced for a given value, and can just use the result in an intuitive way.

Examples ​

shellsession
> jsondecode("{\"hello\": \"world\"}")
{
  "hello" = "world"
}
> jsondecode("true")
true
  • jsonencode performs the opposite operation, encoding a value as JSON.

基于 MPL-2.0 许可证发布。