title: How to change the order of the fields in JSON
body: <p><strong>Scenario</strong>: Consider I have a JSON documents as follows:</p>
  
  <pre><code>   {
       "name": "David",
       "age" : 78,
       "NoOfVisits" : 4
     }
  </code></pre>
  
  <p>Issues: I wanted to change the sequence/order of the fields in the document, say I want <code>age</code>, <code>NoOfVisits</code> &amp; then lastly <code>name</code>.</p>
  
  <p>As of now I am storing the value in temporary variable, deleting the field &amp; recreating the same field. Since the reassignment did not work  :(</p>
  
  <p>I did it in following way: </p>
  
  <pre><code>    temp = doc["age"];
      delete doc['age'];
      doc["age"] = temp;
  
      temp = doc["NoOfVisits "];
      delete doc['NoOfVisits '];
      doc["NoOfVisits"] = temp;
  
      temp = doc["name"];
      delete doc['name'];
      doc["name"] = temp;
  </code></pre>
  
  <p>So that I will get the desired ordered JSON document. This requirement is peculiar kind but still I want some efficient solution</p>
  
  <p><strong>Question</strong>: Can someone help out with efficient way to achieve the same?</p>