[Vuejs]-Is it possible to move a particular JSON key to the top of the JSON using Javascript/VuejJS/Nodejs package?

3👍

A very simplistic approach could be to stringify a new object.

const myObject = {
  "a" : "Value-A",
  "c" : "Value-C",
  "b" : "Value-B",
  "schema" : "2.0"
};

console.log(
  JSON.stringify({
    schema: myObject.schema,
    ...myObject
  }, null, 2)
);

1👍

My suggestion is almost the same as the accepted answer but without using JSON.stringify():

const myObject = {
  "a" : "Value-A",
  "c" : "Value-C",
  "b" : "Value-B",
  "schema" : "2.0"
};

const myReorderedObject = {
  schema: '',
  ...myObject
};

console.log(myReorderedObject);

Leave a comment