Skip to content

Select column cannot find column when parsing json that is missing keys #6969

Closed

Description

@msdrigg

Describe the bug

Consider the following json

> let versions = '[
 {
   "version": "v2.1.0",
   "features": "test"
 },
 {
   "version": "v2.1.1"
 }
]'

We can run the following shell to get a list of features

> $versions | from json | get features
╭───┬──────╮
│ 0 │ test │
│ 1 │      │
╰───┴──────╯

But we cannot select the features column

> $versions | from json | select features 
Error: nu::shell::column_not_found (link)

  × Cannot find column
   ╭─[entry #234:1:1]
 1 │ $versions | from json | select features
   ·            ────┬────          ────┬───
   ·                │                  ╰── cannot find column
   ·                ╰── value originates here
   ╰────

Note, we can select features if we first do a sort-by

> $versions | from json | sort-by version | select features
╭───┬──────────╮
│ # │ features │
├───┼──────────┤
│ 0 │ test     │
│ 1 │          │
╰───┴──────────╯

How to reproduce

  1. Create a table using the following line: let versions = ('[{"version": "v2.1.0", "features": "test"}, {"version": "v2.1.1" }]' | from json)
  2. Try to select the features column $versions | select features
  3. Notice that it errored with Error: nu::shell::column_not_found

Expected behavior

I expect nu to find the column because it looks like it has the column in the table display view, and it can get the column as a list

Screenshots

No response

Configuration

version | transpose key value | to md --pretty

key value
version 0.70.0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.63.0 (4b91a6ea7 2022-08-08)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.63.0 (fd9c4297c 2022-07-01)
pkg_version 0.70.0
build_time 2022-11-01 10:11:57 -04:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins

Additional context

This works if you use either of these json's:

[
  {
    "version": "v2.1.0",
    "features": "test"
  },
  {
    "version": "v2.1.1",
    "features": "hi"
  }
]
[
  {
    "version": "v2.1.0",
    "features": "test"
  },
  {
    "version": "v2.1.1",
    "features": null
  }
]

Activity

  1. changed the title [-]Select column cannot find column but get column can when parsing json that is sometimes missing keys[/-] [+]Select column cannot find column when parsing json that is missing keys[/+] on Nov 1, 2022
  2. added
    category:inconsistent-behavior
    category:bug
    on Nov 1, 2022
  3. fdncred commented on Nov 1, 2022

    @fdncred
    Contributor

    I believe this was recently fixed like this:

    $versions | from json | select -i features 
    ╭───┬──────────╮
    │ # │ features │
    ├───┼──────────┤
    │ 0 │ test     │
    │ 1 │          │
    ├───┼──────────┤
    │ # │ features │
    ╰───┴──────────╯
    

    The -i flag means ignore errors.

    also, get -i works but is a little different

  4. msdrigg commented on Nov 1, 2022

    @msdrigg
    Author

    But why does get work without the -i flag, but select does not. I think it is still unexpected and should be unified.

    I don't know if its possible, but maybe nu should point to the -i flag in the error message.

  5. fdncred commented on Nov 1, 2022

    @fdncred
    Contributor

    maybe it's a bug in get because i think it should complain about the same missing column

  6. kubouch commented on Dec 31, 2022

    @kubouch
    Contributor

    #7002 and #7639 just got merged which should solve this issue. Feel free to reopen or file a new issue if there are still problems.

  7. added this to the v0.74 milestone on Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:bugcategory:inconsistent-behavior

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions