json 파일 만들기

박은정·2021년 8월 27일
1

프로젝트

목록 보기
8/34

가독성을 위해 기존의 상수형태의 목데이터를 → json형태로 변환해서 저장하려고 하는데

json 파일로 변환하는 방법
1. const feedsList = []; 이런 상태였던 거를
{ "feedsList" : [] } 형태로 바꾼다
2. 객체의 key는 문자열이기 때문에 -> 쌍따옴표로 감싼다
3. 따옴표는 홑따옴표는 안되고 오직 쌍따옴표만!

json 더보기

변경전 feedsList 객체

const feedsList = [
  {
    id: 4,
    feedsProfileUrl: './images/eunjungPark/feeds-profile.png',
    userId: 'eunJeong ',
    feedsImageUrl: './images/eunjungPark/feeds-image.png',
    mineProfileUrl: './images/eunjungPark/feeds-profile.png',
    likeUserId: 'chunSig ',
    likeUserNum: '10명',
    commentTitText: '수호가 라이언을 좋아하는구나..!',
  },
  {
    id: 5,
    feedsProfileUrl: './images/eunjungPark/feeds-profile.png',
    userId: 'eunJeong22 ',
    feedsImageUrl: './images/eunjungPark/feeds-image.png',
    mineProfileUrl: './images/eunjungPark/feeds-profile.png',
    likeUserId: 'chunSig22 ',
    likeUserNum: '20명',
    commentTitText: '수호가 라이언을 좋아하는구나..!',
  },
  {
    id: 6,
    feedsProfileUrl: './images/eunjungPark/feeds-profile.png',
    userId: 'eunJeong33 ',
    feedsImageUrl: './images/eunjungPark/feeds-image.png',
    mineProfileUrl: './images/eunjungPark/feeds-profile.png',
    likeUserId: 'chunSig33 ',
    likeUserNum: '30명',
    commentTitText: '수호가 라이언을 좋아하는구나..!',
  },
];

변경후 feedsList.json 파일

{
  "feedsList": [
    {
      "id": 4,
      "feedsProfileUrl": "./images/eunjungPark/feeds-profile.png",
      "userId": "eunJeong ",
      "feedsImageUrl": "./images/eunjungPark/feeds-image.png",
      "mineProfileUrl": "./images/eunjungPark/feeds-profile.png",
      "likeUserId": "chunSig ",
      "likeUserNum": "10명",
      "commentTitText": "수호가 라이언을 좋아하는구나..!"
    },
    {
      "id": 5,
      "feedsProfileUrl": "./images/eunjungPark/feeds-profile.png",
      "userId": "eunJeong22 ",
      "feedsImageUrl": "./images/eunjungPark/feeds-image.png",
      "mineProfileUrl": "./images/eunjungPark/feeds-profile.png",
      "likeUserId": "chunSig22 ",
      "likeUserNum": "20명",
      "commentTitText": "수호가 라이언을 좋아하는구나..!"
    },
    {
      "id": 6,
      "feedsProfileUrl": "./images/eunjungPark/feeds-profile.png",
      "userId": "eunJeong33 ",
      "feedsImageUrl": "./images/eunjungPark/feeds-image.png",
      "mineProfileUrl": "./images/eunjungPark/feeds-profile.png",
      "likeUserId": "chunSig33 ",
      "likeUserNum": "30명",
      "commentTitText": "수호가 라이언을 좋아하는구나..!"
    }
  ]
}
profile
새로운 것을 도전하고 노력한다

0개의 댓글