I am working with Figma API and I am parsing some JSON (this is not my entire JSON FILE). A little context about the JSON file:
- None of these JSON objects are next to each other.
- All JSON objects fall in objects but they appear sequentially
- and their are an unlimited amount of
absoluteBoundingBox
- and the
absoluteBoundingBox
could go by other names I'm not sure what names are or would be.
The issue I'm running into is:
- I need to loop through each
absoluteBoundingBox
- give that
absoluteBoundingBox
a uniqueid
- and its own
x
y
andwidth
andheight
variables` - store those in a new variables so that the variable containing the
objects will need to be created every time a
absoluteBoundingBox
appears.
I know this is a big scope of work. But I need to know where to start.
JSON
[{
id: "6:3",
absoluteBoundingBox: [{
x: -406,
y: -274,
width: 437,
height: 56
}]
}],
[{
id: "10:3",
absoluteBoundingBox: [{
x: -406,
y: -201,
width: 437,
height: 56
}]
}],
[{
id: "10:4",
absoluteBoundingBox: [{
x: -406,
y: -122,
width: 437,
height: 56
}]
}],
[{
id: "10:5",
absoluteBoundingBox: [{
x: -406,
y: -28,
width: 437,
height: 56
}]
}]
JS
const frameJSON = {};
const getFrame =
args.document["children"][0]["children"][0]["absoluteBoundingBox"];
var manyFrames = args.shift().filter(function(v) {
return args.every(function(a) {
return a.indexOf(v) !== -1;
});
});
var FrameID = {};
var textHeight = [];
var textWidth = [];
var textY = [];
var textX = [];
var FrameID = [];
var frameSize = getFrame.keys(getFrame).length;
frameJSON.getFrame = [];
for (b; b > frameJSON; b++) {
if (b < getFrame.frameSize) {
[x] = frameJSON.getFrame.push(getFrame[b].x);
[y] = frameJSON.getFrame.push(getFrame[b].y);
[width] = frameJSON.getFrame.push(getFrame[b].width);
[height] = frameJSON.getFrame.push(getFrame[b].height);
[id] = frameJSON.getFrame.push(getFrame[b].id);
}
}
what is being returned
\ right now I am returning these variables with in my FrameJSON OBJECT I would like to crate atleast 4 FrameJSON objects.
I tried:
const getFrame =
args.document["children"][0]["children"][0]["absoluteBoundingBox"];
const listOfFrames = []
//https://stackoverflow.com/questions/52672037/js-multiple-objects-in-an-array-stored-in-local-storage
getFrame.push('absoluteBoundingBox');
getFrame.push('id');
showList.concat(JSON.parse(localStorage.getItem('listOfFrames')))
localStorage.setItem("listOfFrames", JSON.stringify(listOfFrames));
in order to get a list of frames but the code isn't running like I expected.