Object.toString()
Description
Object.toString()
creates a String representation of a provided Object. This
method is useful for debugging, logging, or when you need a String
representation of complex Objects.
Return value
Type | Description |
---|---|
String representation of the Object. Special characters are properly escaped. |
Examples
Object.toString({a: "test"})
"{ a: \"test\" }"
Nested Object
// Defines an Object with customer data.
let customer = {
"name": "Ruby Von Rails",
"email": "ruby@example.com",
"address": {
"city": "Washington",
"state": "DC"
}
}
Object.toString(customer)
"{ name: \"Ruby Von Rails\", email: \"ruby@example.com\", address: { city: \"Washington\", state: \"DC\" } }"
Object with Multiple Data Types
// Defines an Object.
let data = {
string: "Hello",
number: 42,
boolean: true,
null: null,
array: [1, 2, 3]
}
Object.toString(data)
"{ string: \"Hello\", number: 42, boolean: true, null: null, array: [1, 2, 3] }"
Objects containing document references
// Defines an Object.
let data = {
// Contains a reference to a Category
// collection document.
category: Category.byName("produce").first(),
}
Object.toString(data)
"{ category: { id: ID(\"789\"), coll: Category, ts: Time(\"2099-10-02T22:37:39.583Z\"), products: [set], name: \"produce\", description: \"Fresh Produce\" } }"
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!