github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/doc/content/en/docs/javascript/unmarshal.md (about)

     1  ---
     2  title: "unmarshal"
     3  linkTitle: "unmarshal"
     4  date: 2021-11-20
     5  description: >
     6  
     7  ---
     8  
     9  In the JavaScript environment, there is a `unmarshal` function available that converts a JSON string into an object using the `JSON.parse` function.
    10  
    11  Example implementation of the `unmarshal` function:
    12  
    13  ```javascript
    14  function unmarshal(j) {
    15    return JSON.parse(j);
    16  }
    17  ```
    18  
    19  Example of using the `unmarshal` function:
    20  
    21  ```javascript
    22  var jsonStr = '{"name":"John","age":30,"city":"New York"}';
    23  var obj = unmarshal(jsonStr);
    24  console.log(obj); // { name: "John", age: 30, city: "New York" }
    25  ```
    26  
    27  In this example, the `unmarshal` function takes the JSON string `jsonStr` and uses the `JSON.parse` function to convert the string into an object. The result of the function will be an object containing the data from the JSON string.