Skip to content

How can I save json object in file in order?  #1717

@Linjackffy

Description

@Linjackffy

I create a json object and save it in file:

    json root = {
        {
            "information", {
                {"model", 1},
                {"dof", 6},
                {"aux dof", 0}
            }
        },
        {
            "cartisian limit", {
                {
                    "translation", {
                        {"velocity", 1},
                        {"acceleration", 1},
                        {"deceleration", 1},
                        {"jerk", 1}
                    }
                },
                {
                    "rotation", {
                        {"velocity", 1},
                        {"acceleration", 1},
                        {"deceleration", 1},
                        {"jerk", 1}
                    }
                }
            }
        }
    };
    std::ofstream ob("robot_params.json");
    ob << std::setw(4) << root << std::endl;

And the file robot_params.json looks like this:

{
    "cartisian limit": {
        "rotation": {
            "acceleration": 1,
            "deceleration": 1,
            "jerk": 1,
            "velocity": 1
        },
        "translation": {
            "acceleration": 1,
            "deceleration": 1,
            "jerk": 1,
            "velocity": 1
        }
    },
    "information": {
        "aux dof": 0,
        "dof": 6,
        "model": 1
    }
}

But what I need is saving the json object in order like this:

{
    "information": {
        "model": 1,
        "dof": 6,
        "aux dof": 0
    },
    "cartisian limit": {
        "translation": {
            "velocity": 1,
            "acceleration": 1,
            "deceleration": 1,
            "jerk": 1
        },
        "rotation": {
            "velocity": 1,
            "acceleration": 1,
            "deceleration": 1,
            "jerk": 1
        }
    }
}

Please let me know is it feasible to do so?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions