Serialize nested and recursive structure into flat one with references

109 views Asked by At

clarification: this is a kind of software identification (and I dont know if it is allowed here)
A time ago I saw an app which has made use of a javascript library for transform nested objects into flat one like this

var a = {
  attr1: "some value",
  attr2: new Date(),
  b: {
    attr1: "some other value",
  }
}
a.b.a = a
transform(a)
/*
[{
  ref: 0,
  attr1: {
    type: "string",
    value: "some value"
  },
  attr2: {
    type: "Date",
    value: "2022-03-09T16:17:03.216Z"
  },
  b: {
    type: "ref",
    value: "1"
  }
 },{
  ref: 1,
  attr1: {
    type: "string",
    value: "some other value"
  },
  b: {
    type: "ref",
    value: "0"
  }
}]
*/

Does anyone know of a library or standard for do that?

0

There are 0 answers