Skip to content
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

items() method does not follow order of json message #3278

Closed
1 of 3 tasks
denesh-globotix opened this issue Jan 18, 2022 · 1 comment
Closed
1 of 3 tasks

items() method does not follow order of json message #3278

denesh-globotix opened this issue Jan 18, 2022 · 1 comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@denesh-globotix
Copy link

denesh-globotix commented Jan 18, 2022

What is the issue you have?

Thank you for this library, it has been a real help! I am trying to pass JSON into a c++ code from another Javascript code and everything is working well. One thing I observed however is that the c++ iterator method seems to ignore the order that the JSON keys are in.

Please describe the steps to reproduce the issue.

image

In the print statement above, cleaning_zone_1 is the first key but when printing out the keys using the items() method the order gets changed for some reason

Can you provide a small but working code example?

    // This is the javascript code
   recipe_information = {"cleaning_zone_1":{"coordinates":"[[4.496000216007235, -3.773714192935398], [6.224000241756441, 1.7668573181969796], [2.630857331071582, 3.6868573468072077]]","vacuum":"0","roller":"0","gutter":"0"},"cleaning_zone_2":{"coordinates":"[[-0.6742855753217418, -4.322285629681177], [5.744000234603883, -3.965714195796421], [2.205714467593603, -6.324571373803275]]","vacuum":"1","roller":"0","gutter":"0"},"cleaning_zone_0":{"coordinates":"[[0.8754287334850862, -3.3348570435387743], [6.361143100942885, -0.2628569977624069], [3.7280002045631413, 1.7120001745224003]]","vacuum":"1","roller":"0","gutter":"0"}}

    // This is the c++ code
    auto j3 = json::parse(recipe_information);
    for (auto &el : j3.items())
    {
        std::cout << "key: " << el.key() << ", value:" << el.value() << '\n';
    }

What is the expected behavior?

I was under the impression that the first key, el.key() should have printed out cleaning_zone_1.

And what is the actual behavior instead?

Instead, cleaning_zone_0 is printed out

Which compiler and operating system are you using?

  • Compiler: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
    Copyright (C) 2019 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  • Operating system: Ubuntu 20.04

Which version of the library did you use?

I'm sorry, i'm new to this and am not sure which library it is using. This is listed as part of my ROS dependency which I believe installs from the ROS build farm as listed here: https://index.ros.org/d/nlohmann-json-dev/

  • latest release version 3.10.5
  • other release - please state the version: ___
  • the develop branch
@nlohmann
Copy link
Owner

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed kind: bug labels Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants