Nadav Imergreen
Nadav Imergreen

Reputation: 23

How to Properly Handle NDJSON (JSON Lines) in a React Native Project

I'm working on a React Native project and need to process a .jsonl (NDJSON) file that is stored locally within my project directory. I've been facing issues trying to read and parse this file using various methods and libraries. Here's what I have attempted so far:

import ndjsonStream from 'can-ndjson-stream';

const d = ndjsonStream('../d.jsonl');

However, this approach isn't working as expected. It doesn't seem to correctly handle the local file path or stream the NDJSON data.

  1. Direct Import:
import d from '../d.jsonl';

This method is not supported for NDJSON files, and it throws an error.

  1. Using fetch:
const response = await fetch(filePath);

When I try to fetch the file using this method, I encounter a network error, likely because the file is stored locally and not on a remote server.

My Questions:

Upvotes: 1

Views: 113

Answers (0)

Related Questions