JSON.stringify
Converts JavaScript values to JSON strings; a method of the ECMAScript standard built-in object JSON. Available in JavaScript and Rust strategies; Python strategies use the standard json module.
JSON.stringify(obj)Examples
Serialize an object to a JSON string and output it.
javascript
function main() {
let s1 = {"num": "8754613216564987646512354656874651651358"}
Log("JSON.stringify:", JSON.stringify(s1))
// Output: JSON.stringify: {"num":"8754613216564987646512354656874651651358"}
// JSON.stringify(s1) returns a string
}
rust
fn main() {
// Rust has no JSON.stringify; JsonValue's to_string() prints compact JSON (object keys sorted)
let mut m = std::collections::BTreeMap::new();
m.insert("num".to_string(),
JsonValue::String("8754613216564987646512354656874651651358".to_string()));
let s1 = JsonValue::Object(m);
Log!("JSON.stringify:", s1.to_string());
// Output: JSON.stringify: {"num":"8754613216564987646512354656874651651358"}
}Returns
| Type | Description |
string | Returns the serialized |
Arguments
| Name | Type | Required | Description |
obj | string / number / bool / object / array / function / any | Yes | The value to be serialized into a JSON string. |
See Also
Remarks
Only supported in JavaScript language.