user63898
user63898

Reputation: 30885

How to convert json from text to vaild string

i have json's in text files and i like to embed them into strings in my case cpp is there any tool or utility to do this ? for example i have this long json and i like to concert to valid string .

{
    "rigidBodies": [
        {
            "name": "car_test_mapping",
            "imagePath": "car_body_test.png",
            "origin": {
                "x": 0,
                "y": 0
            },
            "polygons": [
                [
                    {
                        "x": 0.782500028610229,
                        "y": 0.21000000834465
                    },
                    {
                        "x": 0.727500081062317,
                        "y": 0.340000003576279
                    },
                    {
                        "x": 0.179999947547913,
                        "y": 0.422500014305115
                    },
                    {
                        "x": 0.179999947547913,
                        "y": 0.260000020265579
                    }
                ],
                [
                    {
                        "x": 0.179999947547913,
                        "y": 0.260000020265579
                    },
                    {
                        "x": 0.00249993801116943,
                        "y": 0.265000015497208
                    },
                    {
                        "x": 0,
                        "y": -0.00499993562698364
                    },
                    {
                        "x": 0.992500066757202,
                        "y": -0.00499993562698364
                    },
                    {
                        "x": 0.990000009536743,
                        "y": 0.1875
                    },
                    {
                        "x": 0.782500028610229,
                        "y": 0.21000000834465
                    }
                ]
            ],
            "circles": [],
            "shapes": [
                {
                    "type": "POLYGON",
                    "vertices": [
                        {
                            "x": 0.00249993801116943,
                            "y": 0.265000015497208
                        },
                        {
                            "x": 0.179999947547913,
                            "y": 0.260000020265579
                        },
                        {
                            "x": 0.179999947547913,
                            "y": 0.422500014305115
                        },
                        {
                            "x": 0.727500081062317,
                            "y": 0.340000003576279
                        },
                        {
                            "x": 0.782500028610229,
                            "y": 0.21000000834465
                        },
                        {
                            "x": 0.990000009536743,
                            "y": 0.1875
                        },
                        {
                            "x": 0.992500066757202,
                            "y": -0.00499993562698364
                        },
                        {
                            "x": 0,
                            "y": -0.00499993562698364
                        }
                    ]
                }
            ]
        }
    ],
    "dynamicObjects": []
}

Upvotes: 0

Views: 73

Answers (1)

Shahbaz
Shahbaz

Reputation: 3463

You must use JSON.stringify.see documentation

Upvotes: 1

Related Questions