Skip to content

Processing JSON array trigger Passed array keys must be a string. Maybe consider using "array_to_rows()" function? error #1210

@yfktn

Description

@yfktn

I apologize if this is a basic question.

I'm having trouble processing a JSON file where an array lacks key names. Below is a sample of my data:

{
  "draw": null,
  "recordsTotal": 12659,
  "recordsFiltered": 12659,
  "data": [
      [
          "647",
          "Margie Rowe",
          "emailfakefakedata89479@mail.fake.co",
          "E-Purchasing",
          "July 9, 2024",
          "June 1, 2024",
          "Rp. 15,284,386",
          "101753",
          "0",
          "Procurement of Goods",
          "true",
          "true",
          "APBD",
          "52049496",
          "June 1, 2024",
          ""
      ],
      [
          "165",
          "Margie Rowe",
          "emailfakefakedata29002@mail.fake.co",
          "Self-management",
          "March 25, 2024",
          "March 1, 2024",
          "Rp. 81,778,000",
          "60276",
          "1",
          "",
          "false",
          "false",
          "APBD",
          "36070200",
          "December 1, 2024",
          "Type I"
      ]
  ]
}

When I attempt to retrieve the array inside /data, I encounter the following error message:
Passed array keys must be a string. Maybe consider using "array_to_rows()".

Here’s the basic code I’m using:

data_frame()
    ->read(
        from_json(__DIR__ . "/user-data.json", '/data')
    )
    ->write(to_output(false))
    ->run();

And here is the full error message:

#0 /Users/yanf/Projects/belajarjsonmysql/vendor/flow-php/etl/src/Flow/ETL/DSL/functions.php(1063): Flow\ETL\DSL\array_to_row(Array, Object(Flow\ETL\Row\Factory\NativeEntryFactory), Object(Flow\Filesystem\Partitions), NULL)
#1 /Users/yanf/Projects/belajarjsonmysql/vendor/flow-php/etl-adapter-json/src/Flow/ETL/Adapter/JSON/JSONMachine/JsonExtractor.php(44): Flow\ETL\DSL\array_to_rows(Array, Object(Flow\ETL\Row\Factory\NativeEntryFactory), Object(Flow\Filesystem\Partitions), NULL)
#2 [internal function]: Flow\ETL\Adapter\JSON\JSONMachine\JsonExtractor->extract(Object(Flow\ETL\FlowContext))
#3 /Users/yanf/Projects/belajarjsonmysql/vendor/flow-php/etl/src/Flow/ETL/Pipeline/SynchronousPipeline.php(46): Generator->valid()
#4 /Users/yanf/Projects/belajarjsonmysql/vendor/flow-php/etl/src/Flow/ETL/DataFrame.php(738): Flow\ETL\Pipeline\SynchronousPipeline->process(Object(Flow\ETL\FlowContext))
#5 /Users/yanf/Projects/belajarjsonmysql/convert-rup-terumumkan.php(27): Flow\ETL\DataFrame->run()
#6 {main}
  thrown in /Users/yanf/Projects/belajarjsonmysql/vendor/flow-php/etl/src/Flow/ETL/DSL/functions.php on line 1002

Could someone please guide me on how to resolve this issue? Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions