-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The spaces_around_comma options doesn't work #490
Comments
Thanks for reporting this, I'll have a look. |
It's been a while since I've looked at the json options! I had to re-familiarize myself with them. The function If your input JSON looked like [["1", "2"], [3, 4]] you could use jsoncons::json_options options;
options.spaces_around_comma(jsoncons::spaces_option::space_after);
options.array_array_line_splits(jsoncons::line_split_kind::same_line);
std::string buffer;
jsoncons::encode_json(j_arr, buffer, options, jsoncons::indenting::indent);
std::cout << buffer << std::endl; and your output would be
It seems we don't currently have an option for prettifying the output but leaving it on a single line. The name of the fourth parameter type |
Thank you so much for the help! I think I'll iterate the values and format the output by myself then |
This is now supported on the branch jsoncons::json j_arr = jsoncons::json::parse(R"(["1", "2", 3, 4])");
jsoncons::json_options options;
options.spaces_around_comma(jsoncons::spaces_option::space_after) // same as default when using pretty printing
.line_splits(jsoncons::line_split_kind::same_line); // default is multi_line
std::string buffer;
jsoncons::encode_json(j_arr, buffer, options, jsoncons::indenting::indent);
std::cout << buffer << std::endl; Output: ["1", "2", 3, 4] The jsoncons::json j_arr = jsoncons::json::parse(R"(["1", "2", [3, 4]])");
jsoncons::json_options options;
options.line_splits(jsoncons::line_split_kind::same_line);
std::string buffer;
jsoncons::encode_json(j_arr, buffer, options, jsoncons::indenting::indent);
std::cout << buffer << std::endl; produces ["1", "2", [3, 4]] |
That's awsome! Appreciated it! |
<!-- If your PR fixes issues, please note that here by adding "Fixes #NNNNNN." for each fixed issue on separate lines. --> Fixes danielaparker/jsoncons#502 Fixes danielaparker/jsoncons#501 Fixes danielaparker/jsoncons#499 Fixes danielaparker/jsoncons#496 Fixes danielaparker/jsoncons#493 Fixes danielaparker/jsoncons#490 <!-- If you are still working on the PR, open it as a Draft: https://github.blog/2019-02-14-introducing-draft-pull-requests/. --> <!-- If this PR updates an existing port, please uncomment and fill out this checklist: - [x] Changes comply with the [maintainer guide](https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/contributing/maintainer-guide.md). - [x] SHA512s are updated for each updated download. - [x] The "supports" clause reflects platforms that may be fixed by this new version. - [x] Any fixed [CI baseline](https://github.com/microsoft/vcpkg/blob/master/scripts/ci.baseline.txt) entries are removed from that file. - [x] Any patches that are no longer applied are deleted from the port's directory. - [x] The version database is fixed by rerunning `./vcpkg x-add-version --all` and committing the result. - [x] Only one version is added to each modified port's versions file.
<!-- If your PR fixes issues, please note that here by adding "Fixes #NNNNNN." for each fixed issue on separate lines. --> Fixes danielaparker/jsoncons#502 Fixes danielaparker/jsoncons#501 Fixes danielaparker/jsoncons#499 Fixes danielaparker/jsoncons#496 Fixes danielaparker/jsoncons#493 Fixes danielaparker/jsoncons#490 <!-- If you are still working on the PR, open it as a Draft: https://github.blog/2019-02-14-introducing-draft-pull-requests/. --> <!-- If this PR updates an existing port, please uncomment and fill out this checklist: - [x] Changes comply with the [maintainer guide](https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/contributing/maintainer-guide.md). - [x] SHA512s are updated for each updated download. - [x] The "supports" clause reflects platforms that may be fixed by this new version. - [x] Any fixed [CI baseline](https://github.com/microsoft/vcpkg/blob/master/scripts/ci.baseline.txt) entries are removed from that file. - [x] Any patches that are no longer applied are deleted from the port's directory. - [x] The version database is fixed by rerunning `./vcpkg x-add-version --all` and committing the result. - [x] Only one version is added to each modified port's versions file.
I want print out the json array by adding a space after comma. But the spaces_around_comma option doesn't work in the following simple case.
`
Code:
`
The output is:
["1","2",3,4]
What I want is:
["1", "2", 3, 4]
The text was updated successfully, but these errors were encountered: