0

I have below code in react js.

import React from 'react';
import imagesdata from '..data/images.json';

function imagedata() {
  return (

        <div>
      {imagesdata.headerimgs.map((experience, i)=>{
       return (
        <div key={i}>
       <div>
       <h1>{experience.webimg}</h1>
       </div>
       );
                  }
       )
        }
            </div>
  );
}
export default imagedata

After running this code I get error which is

 Parsing error: Unexpected token, expected ","

  19 |   );
  20 | }
> 21 | export default imagedata

1
  • The title is incorrect. The question is not about posting data. Commented Jan 18, 2020 at 8:04

2 Answers 2

2

There is a syntax error in your code. There is an extra div inside map function <div key={i}> *<div>*

import React from "react";
import imagesdata from "../data/images.json";

function imagedata() {
  return (
    <div>
      {imagesdata.headerimgs.map((experience, i) => (
        <div key={i}>
          {" "}
          <h1>{experience.webimg}</h1>
        </div>
      ))}
    </div>
  );
}
export default imagedata;


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

3 Comments

please comment the section which contains the syntax error for clarity.
./src/data/images.json Module parse failed: Unexpected token } in JSON at position 385 while parsing near '...tube.png", } ] }' You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See webpack.js.org/concepts#loaders SyntaxError: Unexpected token } in JSON at position 385 while parsing near '...tube.png", } ] }' at JSON.parse (<anonymous>)
The images.json json file is not in proper format. you can validate the json here jsonlint.com
0

Probably there is an error in one of the import:

import imagesdata from '..data/images.json';

is missing a /. Rewrite it as:

import imagesdata from '../data/images.json';

Comments

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.