Skip to content

Remove cube name prefixes from API response fields in Cube.jsΒ #9893

@CleverFool77

Description

@CleverFool77

Problem

How can I remove cube name prefixes from API response fields in Cube.js?

When querying the Cube.js API, all fields in the response data include the cube name as a prefix (e.g., "combined_tag_analyzer.tag",
"combined_tag_analyzer.tag_count"). I would like to have simplified field names in the response data without these prefixes (e.g., just "tag",
"tag_count").

Related Cube.js schema

  cube(`Tags`, {
    title: `Tags`,
    public: true,
    sql: `
      SELECT 
        itemid,
        network,
        tag,
        'someTags' as tag_type
      FROM media_items 
      ARRAY JOIN someTags AS tag
    `,

    measures: {
      tag_count: {
        type: `count`,
        title: 'count',
        description: 'Count of tag occurrences'
      }
    },

    dimensions: {
      tag: {
        sql: `tag`,
        type: `string`,
        title: `tag`
      },

      tag_type: {
        type: `string`,
        sql: `tag_type`,
        title: `type`
      }
    }
  });

Current Response

  {
    "data": [
      {"Tags.tag": "Green", "Tags.tag_count": "799478"},
      {"Tags.tag": "Screenshot", "Tags.tag_count": "379430"},
      {"Tags.tag": "Clothing", "Tags.tag_count": "307930"}
    ]
  }

Desired Response

  {
    "data": [
      {"tag": "Green", "tag_count": "799478"},
      {"tag": "Screenshot", "tag_count": "379430"},
      {"tag": "Clothing", "tag_count": "307930"}
    ]
  }

I've tried using title, sqlAlias, and creating a view with custom includes, but none of these approaches seem to affect the field names in the actual
API response. Is there a way to configure Cube.js to return simplified field names without the cube name prefixes?
I know i can have custom wrapper in js and i have tried those, But instead would like to know if there is inbuilt functionality in cube ?

Metadata

Metadata

Assignees

Labels

questionThe issue is a question. Please use Stack Overflow for questions.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions