export-from-json icon indicating copy to clipboard operation
export-from-json copied to clipboard

Error: Invalid export data. Please provide an array of object

Open garg10may opened this issue 3 years ago • 19 comments

Error: Invalid export data. Please provide an array of object for a valid object

garg10may avatar Jan 19 '22 15:01 garg10may

can you provide a sample data?

zheeeng avatar Jan 20 '22 01:01 zheeeng

[
    {
        "Test Cohort Version": "5",
        "Study": "CINC280X2105C",
        "Category": "Screen Testing",
        "CheckId": "sdfsdf",
        "Description": "f",
        "Instructions": "sdfds"
    },
    {
        "Test Cohort Version": "5",
        "Study": "CINC280X2105C",
        "Category": "Screen Testing",
        "CheckId": "sfadsfds",
        "Description": "f",
        "Instructions": "sdfds"
    }
]

garg10may avatar Jan 20 '22 01:01 garg10may

Can't reproduce your case. You can fork a repro on https://codepen.io/zheeeng/pen/PQxBKr, I will dig into your issue.

zheeeng avatar Jan 20 '22 02:01 zheeeng

any update?

subhadeepchakraborty avatar Feb 14 '22 12:02 subhadeepchakraborty

This example https://codepen.io/zheeeng/pen/PQxBKr is using your sample data. Can you provide a more concrete example?

zheeeng avatar Feb 15 '22 02:02 zheeeng

I am using the same json structure

subhadeepchakraborty avatar Feb 15 '22 05:02 subhadeepchakraborty

This example works correctly. If any reproduction can be provided will be much helpful to solve your problem.

zheeeng avatar Feb 15 '22 07:02 zheeeng

Help me. I am having the same problem

atakanyurttutann avatar Mar 02 '22 17:03 atakanyurttutann

Help me. I am having the same problem

Please provide repro for contributing debug.

zheeeng avatar Mar 03 '22 03:03 zheeeng

I am facing the same issue. check the screenshot. It's correct data types.
image

rajukumar-rjk avatar Aug 01 '22 02:08 rajukumar-rjk

I am facing the same issue. check the screenshot. It's correct data types. image

I am using it with react

rajukumar-rjk avatar Aug 01 '22 02:08 rajukumar-rjk

@rajukumar-rjk Hey, thx for using. Would you mind posting your sample data here for contributing debug this issue? https://codesandbox.io/s/test-export-from-json-p9qgz2

zheeeng avatar Aug 01 '22 03:08 zheeeng

@rajukumar-rjk Hey, thx for using. Would you mind posting your sample data here for contributing debug this issue? https://codesandbox.io/s/test-export-from-json-p9qgz2

It worked there. but it gives error when I use same data in the react project. I have attached the json exportFromJsonData.txt

rajukumar-rjk avatar Aug 01 '22 05:08 rajukumar-rjk

@rajukumar-rjk Hey, thx for using. Would you mind posting your sample data here for contributing debug this issue? https://codesandbox.io/s/test-export-from-json-p9qgz2

It worked there. but it gives error when I use same data in the react project. I have attached the json exportFromJsonData.txt

Is there some wrapped data structure passed? For example, reactive data created by Mobx or others?

zheeeng avatar Aug 01 '22 06:08 zheeeng

@rajukumar-rjk Hey, thx for using. Would you mind posting your sample data here for contributing debug this issue? https://codesandbox.io/s/test-export-from-json-p9qgz2

It worked there. but it gives error when I use same data in the react project. I have attached the json exportFromJsonData.txt

Is there some wrapped data structure passed? For example, reactive data created by Mobx or others?

No. it just simple array, exactly what I have shared with you.

rajukumar-rjk avatar Aug 01 '22 06:08 rajukumar-rjk

@rajukumar-rjk export-from-json asserts input data is Array via such implementation https://github.com/zheeeng/export-from-json/blob/master/src/utils.ts#L1-L3, if possible you can try test your input's type.

zheeeng avatar Aug 01 '22 07:08 zheeeng

@garg10may try this

let data = [
    {
        "Test Cohort Version": "5",
        "Study": "CINC280X2105C",
        "Category": "Screen Testing",
        "CheckId": "sdfsdf",
        "Description": "f",
        "Instructions": "sdfds"
    },
    {
        "Test Cohort Version": "5",
        "Study": "CINC280X2105C",
        "Category": "Screen Testing",
        "CheckId": "sfadsfds",
        "Description": "f",
        "Instructions": "sdfds"
    }
]

let fileName = 'example'
let exportType = exportFromJSON.types.xls;
exportFromJSON({ data: data, fileName: fileName, exportType: exportType })

it's work in my case

ricko-v avatar Aug 11 '22 02:08 ricko-v

@garg10may try this

let data = [
    {
        "Test Cohort Version": "5",
        "Study": "CINC280X2105C",
        "Category": "Screen Testing",
        "CheckId": "sdfsdf",
        "Description": "f",
        "Instructions": "sdfds"
    },
    {
        "Test Cohort Version": "5",
        "Study": "CINC280X2105C",
        "Category": "Screen Testing",
        "CheckId": "sfadsfds",
        "Description": "f",
        "Instructions": "sdfds"
    }
]

let fileName = 'example'
let exportType = exportFromJSON.types.xls;
exportFromJSON({ data: data, fileName: fileName, exportType: exportType })

it's work in my case

This solve my problem too.

rajukumar-rjk avatar Aug 11 '22 08:08 rajukumar-rjk

Arrays are a special type of object. The typeof operator in JavaScript returns "object" for arrays.

When I console logged my data, I found that my data was structured as image

So the solution was to use const data = Object.values(result) and pass the data to the exportFromJSON

PaulleDemon avatar Aug 31 '22 12:08 PaulleDemon

Hi Is there any way to add (sep=, ) in an export JSON file top? for some European users, we are seeing in something diff format.

image

add Like this: image

anil-pamerapu avatar Jan 11 '23 16:01 anil-pamerapu