1

I just upgraded to Ruby 5.1.4 and some of my previously working javascript code stopped working and i cant seem to figure out why.

Every time i set the properties of an object like this

    FLOW.nodes.forEach( function( node ) {
    _nodes.push({
        "step_type":            node.type,
        "internal_id":          node.getId({ useMap: useMap }),
        "step_attributes" : {
            "shape":                node.shape,
            "icon":                 node.icon,
            "title":                node.title,
            "subtitle":             node.subTitle,
            "connectors":           JSON.stringify( node.connectors ),
            "tags":                 JSON.stringify( node.tags ),
            "allowed_connections":  JSON.stringify( node.allowedConnections ),
            "position":             JSON.stringify( node.position ),
            "configured":           node.configured,
            "socket":               JSON.stringify( node.socket ),
            "buttons":              JSON.stringify( node.buttons ),
            "color":                node.color
        },
        "properties":            JSON.stringify( FLOW.getNodeProperties( node.getId() ) )
    });
});

every-time i save it keeps adding more backslashes to properties and i cant figure out why

here is what it prints out like

"properties": "\"{\\\"tags\\\": \\\"erewerwre\\\",\\\"tagged_present\\\": true,\\\"tagged_future\\\": false,\\\"tagged_present_future\\\": false,\\\"remove_from_other_flows\\\": false}\""

If it runs through there again it will keep adding more backslashes.

any idea how i can fix this?

1
  • Why are you calling stringify inside of JavaScript? This will, obviously, create duplicate quotes. You're working with a JavaScript object directly. The quotes on the keys are extraneous, this isn't JSON data. It's JavaScript data. Commented Jan 22, 2018 at 18:19

1 Answer 1

1

Looking at the code and result, FLOW.getNodeProperties is returning a string containing JSON. By applying JSON.stringify to it, you're encoding it a second time, e.g.:

function getNodeProperties() {
  return JSON.stringify({some: "property"});
}
var result = {
  properties: JSON.stringify(getNodeProperties())
};
console.log(result.properties);

Just remove your JSON.stringify call:

"properties": FLOW.getNodeProperties( node.getId() )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.