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

Get an Index or row number of an element #1186

Closed
CleanHit opened this issue Aug 3, 2018 · 4 comments
Closed

Get an Index or row number of an element #1186

CleanHit opened this issue Aug 3, 2018 · 4 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@CleanHit
Copy link

CleanHit commented Aug 3, 2018

Let say I have this file:

{
  "tableName": "",
  "tableSchemaName": "",
  "_comment": "",
  "0": ["","", "", ""],
  "1": ["", "", "", ""],
  "2": ["", "", "", ""],
  "3": ["", "", "", ""],
  "4": ["", "", "", ""]
}

Is there a way to get the index or row_number of "0"? I didn't see it in the document.

@gregmarr
Copy link
Contributor

gregmarr commented Aug 3, 2018

No, that's not an array, it's an object, which is an unordered collection of name/value pairs, so there is no index.

@CleanHit
Copy link
Author

CleanHit commented Aug 4, 2018

I see. So basically I have to remember myself how many lines I have before the "0" starts or save the keys in some kind of ordered structure, if I have to iterate over the keys with numbers. I need it for my loop size.

@nlohmann
Copy link
Owner

nlohmann commented Aug 4, 2018

It seems as if an object is not really the right way to model your usecase (as its keys are unordered). Unless you can change this, using a secondary structure to organize the order of keys seems to be the only way.

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Aug 4, 2018
@CleanHit
Copy link
Author

CleanHit commented Aug 4, 2018

Got it, thanks.

@CleanHit CleanHit closed this as completed Aug 4, 2018
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

3 participants