0

i have a python script that create a json and i have a nodejs script that read the json:

  • python script
with open("music.json", "w") as write_file:
    json.dump(music_found, write_file, indent=4)

music_found is an array of object

  • nodejs
import fs from 'fs'
import { cwd } from 'process';


let rawdata = fs.readFileSync(`${cwd()}/music.json`);
let music = JSON.parse(rawdata)
console.log(music);

i get the message unexpected end of json input

  • json example
[
    {
        "user": "some_user1",
        "file": "@@enlbq\\_Music\\Infected Mushroom\\Return to the Sauce [2017] [HMCD94]\\09 - Infected Mushroom - Liquid Smoke.flac",
        "size": 42084572,
        "slots": true,
        "speed": 1003176
    },
    {
        "user": "some_user2",
        "file": "@@xfjpb\\Musiikkia\\Infected Mushroom\\Return to the Sauce\\09 Infected Mushroom - Liquid Smoke.flac",
        "size": 24617421,
        "slots": true,
        "speed": 541950
    },
    {
        "user": "some_user3",
        "file": "@@rxjpv\\MyMusic\\Infected Mushroom\\Infected Mushroom - Return To The Sauce (2017) [CD FLAC]\\09 - Liquid Smoke.flac",
        "size": 41769608,
        "slots": true,
        "speed": 451671
    }
]

my json is well formatted no ? i'm on that since 4hours and im stuck on it... very annoying ^^ hope somehone help

2
  • 1
    stackoverflow.com/a/1505477/8150371 Commented Aug 20, 2020 at 15:11
  • Try using encodeURIComponent() to make the file name safe for JSON. though will have to decode it before using but it will make your life easy. Commented Aug 20, 2020 at 15:41

2 Answers 2

1

readFileSync

If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.

You need to either set the encoding or use the buffer's .toString() method

Sign up to request clarification or add additional context in comments.

1 Comment

when i use the nodejs script it works but when i call it from python with subprocess.call its doesnt and i have the unexpected end of json input... (i do that because i don't find a equivalent npm package for python)
0

Can you make sure the path is correct ? i can read your data normally in js so i think the problem is just the path

1 Comment

the path is correct when i console.log it, i don't have to use cwd tho but try something since im stuck, u can read it normally ? pls tell me what do you do ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.