×

注意!页面内容来自https://qiita.com/inokage/items/7ff5d5a41a960a75bfb7,本站不储存任何内容,为了更好的阅读体验进行在线解析,若有广告出现,请及时反馈。若您觉得侵犯了您的利益,请通知我们进行删除,然后访问 原网页

< data-emotion="-global ffh7zq">.-ffh7zq{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:56px;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;padding:16px 24px 0;}@media (max-width: 1199px){.-ffh7zq{gap:24px;}}@media (max-width: 769px){.-ffh7zq{padding:16px 16px 0;}}@media (max-width: 479px){.-ffh7zq{padding:16px 0 0;}}< data-emotion="-global 1hl01qi">.-1hl01qi{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;gap:16px;height:-webkit-fit-content;height:-moz-fit-content;height:fit-content;position:-webkit-sticky;position:sticky;top:40px;z-index:5;}@media (max-width: 769px){.-1hl01qi{display:none;}}< data-emotion="-global c1wjhj">.-c1wjhj{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;cursor:pointer;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:0;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;}< data-emotion="-global 1kcqgjb">.-1kcqgjb{height:44px;width:44px;position:relative;}.-1kcqgjb svg{cursor:auto;pointer-events:none;}< data-emotion="-global 1e9ifl5">.-1e9ifl5{fill:none;left:50%;position:absolute;top:50%;-webkit-transform:translate(-50%-50%);-moz-transform:translate(-50%-50%);-ms-transform:translate(-50%-50%);transform:translate(-50%-50%);}.-1e9ifl5 .circle,.-1e9ifl5 .heart-stroke,.-1e9ifl5 .heart-fill,.-1e9ifl5 .particle{-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out;transform-origin:center center;}.-1e9ifl5 .circle{fill:var(--color-surface);stroke:var(--color-divider);stroke-width:1;}.-1e9ifl5 .heart-stroke{fill:var(--color-mediumEmphasis);}.-1e9ifl5 .heart-fill{fill:var(--color-qiitaGreen);opacity:0;}.-1e9ifl5 .particles{rotate:var(--rotate);transform-origin:center center;}.-1e9ifl5 .particle{opacity:0;}.-1e9ifl5.liked .circle{-webkit-animation-delay:90ms;animation-delay:90ms;-webkit-animation-duration:60ms;animation-duration:60ms;-webkit-animation-name:animation-1n63bow;animation-name:animation-1n63bow;}.-1e9ifl5.liked .heart-stroke{-webkit-animation-duration:150ms;animation-duration:150ms;-webkit-animation-name:animation-d4tj02;animation-name:animation-d4tj02;}.-1e9ifl5.liked .heart-fill{-webkit-animation-delay:150ms;animation-delay:150ms;-webkit-animation-duration:100ms;animation-duration:100ms;-webkit-animation-name:animation-19addpb;animation-name:animation-19addpb;}.-1e9ifl5.liked .particle{-webkit-animation-delay:150ms;animation-delay:150ms;-webkit-animation-duration:var(--duration);animation-duration:var(--duration);-webkit-animation-name:animation-1spcwjj;animation-name:animation-1spcwjj;}< data-emotion="-global animation-1n63bow">@-webkit-keyframes animation-1n63bow{100%{stroke:var(--color-qiitaGreen);}}@keyframes animation-1n63bow{100%{stroke:var(--color-qiitaGreen);}}< data-emotion="-global animation-d4tj02">@-webkit-keyframes animation-d4tj02{40%{fill:currentColor;scale:0.85;}100%{fill:var(--color-qiitaGreen);}}@keyframes animation-d4tj02{40%{fill:currentColor;scale:0.85;}100%{fill:var(--color-qiitaGreen);}}< data-emotion="-global animation-19addpb">@-webkit-keyframes animation-19addpb{1%{scale:1.2;opacity:1;}100%{scale:1;opacity:1;}}@keyframes animation-19addpb{1%{scale:1.2;opacity:1;}100%{scale:1;opacity:1;}}< data-emotion="-global animation-1spcwjj">@-webkit-keyframes animation-1spcwjj{1%{opacity:1;}90%{opacity:1;}100%{cx:var(--x);cy:var(--y);opacity:0;}}@keyframes animation-1spcwjj{1%{opacity:1;}90%{opacity:1;}100%{cx:var(--x);cy:var(--y);opacity:0;}}< data-emotion="-global 12lwyvn">.-12lwyvn{background-color:transparent;border:none;cursor:pointer;height:44px;padding:0;position:absolute;width:44px;}.-12lwyvn:disabled{cursor:not-allowed;}< data-emotion="-global wknrvb">@media (max-width: 769px){.-wknrvb{display:block;}}< data-emotion="-global 3fim88">.-3fim88{position:relative;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;}< data-emotion="-global 1a6dkvp">.-1a6dkvp{color:var(--color-mediumEmphasis);cursor:pointer;font-size:var(--font-size-body-2);font-weight:bold;}< data-emotion="-global wvpanj">.-wvpanj{background-color:var(--color-grayContainer);border-radius:4px;color:var(--color-onContainerText);font-size:var(--font-size-body-3);max-width:280px;overflow-wrap:break-word;padding:4px 8px;position:absolute;pointer-events:none;display:none;width:-webkit-max-content;width:-moz-max-content;width:max-content;z-index:1;top:50%;-webkit-transform:translateY(-50%);-moz-transform:translateY(-50%);-ms-transform:translateY(-50%);transform:translateY(-50%);left:calc(100% + 0px + 4px);}.-wvpanj::after{background-color:var(--color-grayContainer);content:"";position:absolute;}< data-emotion="-global 1bc9a2c">.-1bc9a2c{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;gap:0;position:relative;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;}< data-emotion="-global 1h3mu5f">.-1h3mu5f{display:inline-block;fill:var(--color-mediumEmphasis);height:28px;width:28px;}< data-emotion="-global 1vem4tk">.-1vem4tk{color:var(--color-mediumEmphasis);font-size:14px;font-weight:bold;}@media (max-width: 769px){.-1vem4tk{display:inline;}}< data-emotion="-global 18p0hi4">.-18p0hi4{border:none;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;background-color:transparent;border:none;color:var(--color-mediumEmphasis);cursor:pointer;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:20px;height:44px;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;padding:0;width:44px;}< data-emotion="-global z8ff57">.-z8ff57{height:24px;fill:var(--color-twitter);width:24px;}< data-emotion="-global 1qsoaul">.-1qsoaul{background-color:var(--color-grayContainer);border-radius:4px;color:var(--color-onContainerText);font-size:var(--font-size-body-3);max-width:280px;overflow-wrap:break-word;padding:4px 8px;position:absolute;pointer-events:none;display:none;width:-webkit-max-content;width:-moz-max-content;width:max-content;z-index:1;top:50%;-webkit-transform:translateY(-50%);-moz-transform:translateY(-50%);-ms-transform:translateY(-50%);transform:translateY(-50%);left:calc(100% + -4px + 4px);}.-1qsoaul::after{background-color:var(--color-grayContainer);content:"";position:absolute;}< data-emotion="-global lgaqil">.-lgaqil{height:24px;fill:#1877f2;width:24px;}< data-emotion="-global 1m01c8l">.-1m01c8l{height:24px;width:24px;}< data-emotion="-global 79elbk">.-79elbk{position:relative;}< data-emotion="-global v2p563">.-v2p563{display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:24px;height:24px;overflow:hidden;width:24px;}< data-emotion="-global oi42s2">.-oi42s2:modal{background-color:transparent;border:none;max-height:none;max-width:none;width:100%;height:100dvh;display:grid;place-items:center;padding:16px;}.-oi42s2::backdrop{background-color:rgb(0 0 0 / .32);}< data-emotion="-global 2aaf4j">.-2aaf4j{background-color:var(--color-surface);border-radius:8px;color:var(--color-highEmphasis);max-width:600px;max-height:calc(100vh - 160px);overflow-y:auto;padding:24px;width:100%;scrollbar-width:thin;scrollbar-color:var(--scrollbar-color-scrollbarThumb) transparent;}.-2aaf4j::-webkit-scrollbar{width:8px;}.-2aaf4j::-webkit-scrollbar-track{background:transparent;}.-2aaf4j::-webkit-scrollbar-thumb{background:var(--scrollbar-color-scrollbarThumb);border-radius:4px;}< data-emotion="-global bxc62b">.-bxc62b{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;border-bottom:1px solid var(--color-divider);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;padding-bottom:8px;}< data-emotion="-global 1snuvpu">.-1snuvpu{font-size:var(--font-size-subhead-2);font-weight:600;line-height:1.4;}< data-emotion="-global o8tyjw">.-o8tyjw{background-color:transparent;color:var(--color-mediumEmphasis);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;padding:4px;}< data-emotion="-global 6vdptm">.-6vdptm{font-size:var(--font-size-body-1);margin-top:16px;}< data-emotion="-global 111ab2g">.-111ab2g{border-top:1px solid var(--color-divider);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-flex-wrap:wrap;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:16px;-webkit-box-pack:end;-ms-flex-pack:end;-webkit-justify-content:flex-end;justify-content:flex-end;margin-top:16px;padding-top:16px;}< data-emotion="-global hreeih">.-hreeih{border-radius:8px;box-sizing:border-box;cursor:pointer;display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:16px;font-weight:600;line-height:1.8;margin-bottom:0;min-height:34px;min-width:64px;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;white-space:nowrap;-webkit-transition:.1s ease-out;transition:.1s ease-out;transition-property:background-color,border-color;background-color:var(--color-surface);border:1px solid var(--color-grayBorder);color:var(--color-grayText);padding:3px 15px;}.-hreeih:disabled{box-shadow:none;cursor:not-allowed;opacity:0.32;}.-hreeih:active{background-color:var(--color-background);}@media (hover: hover) and (pointer: fine){.-hreeih:hover{background-color:var(--color-background);}}< data-emotion="-global y54waz">.-y54waz{border-radius:8px;box-sizing:border-box;cursor:pointer;display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:16px;font-weight:600;line-height:1.8;margin-bottom:0;min-height:34px;min-width:64px;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;white-space:nowrap;-webkit-transition:.1s ease-out;transition:.1s ease-out;transition-property:background-color,border-color;background-color:var(--color-redContainer);color:var(--color-onContainerText);padding:4px 16px;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:4px;}.-y54waz:disabled{box-shadow:none;cursor:not-allowed;opacity:0.32;}.-y54waz:active{background-color:var(--color-redContainerDim);}@media (hover: hover) and (pointer: fine){.-y54waz:hover{background-color:var(--color-redContainerDim);}}< data-emotion="-global 1jvcm2e">.-1jvcm2e{display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:16px;height:16px;overflow:hidden;width:16px;}< data-emotion="-global 1hbd3g7">.-1hbd3g7{height:250px;}< data-emotion="-global uaiz0z">.-uaiz0z{height:90px;margin-bottom:32px;}@media (max-width: 1227px){.-uaiz0z{height:50px;}}@media (max-width: 769px){.-uaiz0z{display:none;}}< data-emotion="-global itrjxe">.-itrjxe{background-color:var(--color-surface);border-radius:8px;padding:32px 56px;margin-bottom:24px;}@media (max-width: 769px){.-itrjxe{padding:24px 32px;}}@media (max-width: 479px){.-itrjxe{border-radius:0;margin:0 0 40px;padding:24px 16px;}}< data-emotion="-global 1cpeld6">.-1cpeld6{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-color:var(--color-yellowContainerVariant);border-radius:8px;color:var(--color-highEmphasis);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:var(--font-size-body-2);font-weight:600;gap:8px;line-height:1.5;margin-bottom:16px;padding:16px;}< data-emotion="-global 1l7bzw8">.-1l7bzw8{display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:24px;height:24px;overflow:hidden;width:24px;color:var(--color-yellowText);}< data-emotion="-global 8qb8m4">.-8qb8m4{margin-bottom:48px;}< data-emotion="-global 1yndj8s">.-1yndj8s{display:grid;gap:8px;margin-bottom:16px;}< data-emotion="-global 1n13dr3">.-1n13dr3{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-color:var(--color-red70);background-image:url(//cdn.qiita.com/assets/public/client-resources/back-advent_calendar_ribbon-d101367e94b165b1-d101367e94b165b1.png);background-repeat:repeat-x;-webkit-background-size:auto 100%;background-size:auto 100%;border-radius:8px;color:var(--advent-calendar-color-whiteText);display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;gap:4px;max-width:100%;overflow:hidden;padding:8px 12px;}< data-emotion="-global 1t9pz9x">.-1t9pz9x{width:20px;height:20px;}< data-emotion="-global 1n1ctis">.-1n1ctis{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;overflow:hidden;}< data-emotion="-global 1vnzwvc">.-1vnzwvc{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:inherit;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:4px;padding-block:4px;}< data-emotion="-global u4aylv">.-u4aylv{background-color:var(--advent-calendar-color-whiteText);border-radius:4px;color:var(--color-red70);font-size:var(--font-size-body-3);font-weight:600;line-height:var(--line-height-body-dense);padding:2px 4px;min-width:50px;text-align:center;}< data-emotion="-global lfd7oi">.-lfd7oi{font-size:var(--font-size-body-2);font-weight:600;line-height:var(--line-height-body-dense);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}< data-emotion="-global i43zkt">.-i43zkt{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:var(--font-size-body-2);gap:0 8px;line-height:var(--line-height-body);width:100%;}< data-emotion="-global 17gh4w8">.-17gh4w8{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-flex-wrap:wrap;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:0 8px;width:calc(100% - 40px);}< data-emotion="-global mavs84">.-mavs84{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:var(--color-highEmphasis);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:var(--font-size-body-1);font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%;}< data-emotion="-global kcbbwa">.-kcbbwa{border-radius:50%;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;overflow:hidden;position:relative;width:24px;height:24px;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;margin-right:8px;}.-kcbbwa::before{background-color:var(--color-gray0);border-radius:50%;content:"";height:23px;left:50%;position:absolute;top:50%;-webkit-transform:translate(-50%-50%);-moz-transform:translate(-50%-50%);-ms-transform:translate(-50%-50%);transform:translate(-50%-50%);width:23px;}< data-emotion="-global 1wqqt93">.-1wqqt93{display:block;height:24px;object-fit:contain;position:relative;width:24px;}< data-emotion="-global 1e7czb6">.-1e7czb6{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;gap:0 4px;max-width:100%;}< data-emotion="-global 1o5v0u9">.-1o5v0u9{color:var(--color-highEmphasis);font-weight:600;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:0 4px;max-width:calc(100% - 12px);}< data-emotion="-global rdqgjc">.-rdqgjc{background-color:var(--color-gray0);border-radius:4px;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;height:20px;object-fit:contain;width:20px;}< data-emotion="-global 8uhtka">.-8uhtka{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}< data-emotion="-global wo2a1i">.-wo2a1i{font-size:28px;font-weight:600;line-height:var(--line-height-headline);margin-top:8px;word-break:break-all;}< data-emotion="-global 28f073">.-28f073{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-flex-wrap:wrap;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:4px;margin-top:16px;}< data-emotion="-global 19h8hex">.-19h8hex{background-color:var(--color-surfaceVariant);border-radius:4px;color:var(--color-mediumEmphasis);display:block;font-size:var(--font-size-body-2);line-height:var(--line-height-body-dense);padding:0 6px;position:relative;z-index:1;}.-19h8hex:active{-webkit-text-decoration:none;text-decoration:none;background-color:var(--color-surfaceVariantDim);}@media (hover: hover) and (pointer: fine){.-19h8hex:hover{-webkit-text-decoration:none;text-decoration:none;background-color:var(--color-surfaceVariantDim);}}< data-emotion="-global 164r41r">.-164r41r{margin-top:8px;}< data-emotion="-global xxdqwu">.-xxdqwu{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-flex-wrap:wrap;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}< data-emotion="-global qxeflw">.-qxeflw{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:2px;margin-right:8px;}< data-emotion="-global 1escyri">.-1escyri{display:inline-block;fill:var(--color-mediumEmphasis);height:20px;vertical-align:middle;width:20px;}< data-emotion="-global djk6ka">.-djk6ka{font-size:var(--font-size-body-2);}< data-emotion="-global 1npej5s">.-1npej5s{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-flex-wrap:wrap;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;font-size:var(--font-size-body-2);gap:0 8px;margin-top:8px;}< data-emotion="-global 1r3vbu3">.-1r3vbu3{display:grid;gap:24px;margin-top:32px;}< data-emotion="-global gg4vpm">.-gg4vpm{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;}< data-emotion="-global 1f18zs1">.-1f18zs1{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:16px;}< data-emotion="-global aaiy04">.-aaiy04{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;cursor:pointer;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:4px;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;}< data-emotion="-global buogjo">@media (max-width: 769px){.-buogjo{display:none;}}< data-emotion="-global yz0xtg">.-yz0xtg{background-color:var(--color-grayContainer);border-radius:4px;color:var(--color-onContainerText);font-size:var(--font-size-body-3);max-width:280px;overflow-wrap:break-word;padding:4px 8px;position:absolute;pointer-events:none;display:none;width:-webkit-max-content;width:-moz-max-content;width:max-content;z-index:1;bottom:calc(100% + 0px + 4px);left:50%;-webkit-transform:translateX(-50%);-moz-transform:translateX(-50%);-ms-transform:translateX(-50%);transform:translateX(-50%);}.-yz0xtg::after{background-color:var(--color-grayContainer);content:"";position:absolute;}< data-emotion="-global izmm4j">.-izmm4j{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;gap:4px;position:relative;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;}< data-emotion="-global 1129w32">.-1129w32{color:var(--color-mediumEmphasis);font-size:14px;font-weight:bold;}@media (max-width: 769px){.-1129w32{display:none;}}< data-emotion="-global fy7cii">.-fy7cii{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;border-radius:4px;color:var(--color-highEmphasis);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:var(--font-size-body-2);gap:4px;padding:4px;}.-fy7cii:active{background-color:var(--color-surfaceVariant);-webkit-text-decoration:none;text-decoration:none;}@media (hover: hover) and (pointer: fine){.-fy7cii:hover{background-color:var(--color-surfaceVariant);-webkit-text-decoration:none;text-decoration:none;}}< data-emotion="-global 810jp8">.-810jp8{display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:24px;height:24px;overflow:hidden;width:24px;color:var(--color-mediumEmphasis);}< data-emotion="-global rwy56f">.-rwy56f{background-image:url(//cdn.qiita.com/assets/public/image-qiitan_for_login_modal-014e085d3e40a240e3fe8d61b70b29a9.png);-webkit-background-position:bottom 24px right 24px;background-position:bottom 24px right 24px;background-repeat:no-repeat;-webkit-background-size:140px;background-size:140px;border:1px solid var(--color-greenBorder);border-radius:8px;margin:40px auto 0;max-width:572px;padding:24px;}@media (max-width: 769px){.-rwy56f{width:100%;background-image:none;}}< data-emotion="-global 1nyasl8">.-1nyasl8{font-size:var(--font-size-subhead-1);font-weight:600;line-height:1.4;}@media (max-width: 769px){.-1nyasl8{font-size:var(--font-size-subhead-2);}}< data-emotion="-global 1i89dtz">.-1i89dtz{font-size:var(--font-size-body-1);font-weight:600;list--position:inside;margin-top:16px;}@media (max-width: 769px){.-1i89dtz{font-size:var(--font-size-body-2);}}< data-emotion="-global dzaums">.-dzaums{display:inline-block;font-size:var(--font-size-body-2);margin-top:16px;-webkit-text-decoration:underline;text-decoration:underline;}< data-emotion="-global geahq7">.-geahq7{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:16px;margin-top:16px;}@media (max-width: 769px){.-geahq7{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}}< data-emotion="-global 1dq3d3h">.-1dq3d3h{border-radius:8px;box-sizing:border-box;display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:16px;font-weight:600;line-height:1.8;min-height:34px;min-width:64px;opacity:1;pointer-events:auto;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;white-space:nowrap;-webkit-transition:.1s ease-out;transition:.1s ease-out;transition-property:background-color,border-color;background-color:var(--color-greenContainer);color:var(--color-onContainerText);padding:4px 16px;gap:16px;}.-1dq3d3h:hover{-webkit-text-decoration:none;text-decoration:none;}.-1dq3d3h:active{background-color:var(--color-greenContainerDim);}@media (hover: hover) and (pointer: fine){.-1dq3d3h:hover{background-color:var(--color-greenContainerDim);}}@media (max-width: 769px){.-1dq3d3h{width:100%;}}< data-emotion="-global tfrxbl">.-tfrxbl{border-radius:8px;box-sizing:border-box;display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:16px;font-weight:600;line-height:1.8;min-height:34px;min-width:64px;opacity:1;pointer-events:auto;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;white-space:nowrap;-webkit-transition:.1s ease-out;transition:.1s ease-out;transition-property:background-color,border-color;background-color:var(--color-surface);border:1px solid var(--color-grayBorder);color:var(--color-grayText);padding:3px 15px;gap:16px;}.-tfrxbl:hover{-webkit-text-decoration:none;text-decoration:none;}.-tfrxbl:active{background-color:var(--color-background);}@media (hover: hover) and (pointer: fine){.-tfrxbl:hover{background-color:var(--color-background);}}@media (max-width: 769px){.-tfrxbl{width:100%;}}< data-emotion="-global qp8zqs">.-qp8zqs{background-color:var(--color-surface);border-radius:32px;bottom:8px;box-shadow:0px 1px 1px 0px rgba(3033330.25),0px 0px 0px 1px var(--elevation-color-elevationDivider);display:none;height:44px;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;left:0;margin-inline:auto;position:fixed;right:0;-webkit-transition:bottom 0.2s ease-out;transition:bottom 0.2s ease-out;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;z-index:10;}@media (max-width: 769px){.-qp8zqs{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}}< data-emotion="-global 1bsmiz1">.-1bsmiz1{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:12px;-webkit-box-pack:space-evenly;-ms-flex-pack:space-evenly;-webkit-justify-content:space-evenly;justify-content:space-evenly;min-width:260px;padding:0 24px;}< data-emotion="-global 12jqd09">.-12jqd09{fill:none;left:50%;position:absolute;top:50%;-webkit-transform:translate(-50%-50%);-moz-transform:translate(-50%-50%);-ms-transform:translate(-50%-50%);transform:translate(-50%-50%);}.-12jqd09 .circle,.-12jqd09 .heart-stroke,.-12jqd09 .heart-fill,.-12jqd09 .particle{-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out;transform-origin:center center;}.-12jqd09 .circle{fill:var(--color-surface);stroke:var(--color-divider);stroke-width:1;}.-12jqd09 .heart-stroke{fill:var(--color-mediumEmphasis);}.-12jqd09 .heart-fill{fill:var(--color-qiitaGreen);opacity:0;}.-12jqd09 .particles{rotate:var(--rotate);transform-origin:center center;}.-12jqd09 .particle{opacity:0;}.-12jqd09.liked .circle{-webkit-animation-delay:90ms;animation-delay:90ms;-webkit-animation-duration:60ms;animation-duration:60ms;-webkit-animation-name:animation-1n63bow;animation-name:animation-1n63bow;}.-12jqd09.liked .heart-stroke{-webkit-animation-duration:150ms;animation-duration:150ms;-webkit-animation-name:animation-d4tj02;animation-name:animation-d4tj02;}.-12jqd09.liked .heart-fill{-webkit-animation-delay:150ms;animation-delay:150ms;-webkit-animation-duration:100ms;animation-duration:100ms;-webkit-animation-name:animation-19addpb;animation-name:animation-19addpb;}.-12jqd09.liked .particle{-webkit-animation-delay:150ms;animation-delay:150ms;-webkit-animation-duration:var(--duration);animation-duration:var(--duration);-webkit-animation-name:animation-1spcwjj;animation-name:animation-1spcwjj;}.-12jqd09 .circle{stroke:transparent;}.-12jqd09.liked .circle{-webkit-animation-name:animation-6fz0t5;animation-name:animation-6fz0t5;}< data-emotion="-global animation-6fz0t5">@-webkit-keyframes animation-6fz0t5{100%{stroke:transparent;}}@keyframes animation-6fz0t5{100%{stroke:transparent;}}< data-emotion=" cxm9xv 16dfkpu sji4h7 3k9iaf 9wqfmg">.-cxm9xv{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;background-color:var(--color-surface);border:1px solid var(--color-divider);border-radius:50%;cursor:pointer;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;height:44px;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;width:44px;}.-16dfkpu{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;background-color:transparent;border:none;color:var(--color-mediumEmphasis);cursor:pointer;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:20px;height:44px;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;padding:0;width:44px;}.-sji4h7{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;background-color:transparent;border:none;border-radius:50%;color:var(--color-mediumEmphasis);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:var(--font-size-subhead-1);height:44px;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;padding:0;width:44px;}.-3k9iaf{color:var(--color-mediumEmphasis);}.-9wqfmg{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;background-color:var(--color-surface);border:none;border-radius:50%;cursor:pointer;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;height:44px;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;width:44px;}< data-emotion="-global 1736035">.-1736035{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:var(--font-size-body-2);font-weight:600;list-:none;max-width:1656px;overflow-x:auto;padding:0 32px;width:100%;scrollbar-width:thin;scrollbar-color:var(--scrollbar-color-scrollbarThumb) transparent;}.-1736035::-webkit-scrollbar{height:8px;}.-1736035::-webkit-scrollbar-track{background:transparent;}.-1736035::-webkit-scrollbar-thumb{background:var(--scrollbar-color-scrollbarThumb);border-radius:4px;}@media (max-width: 769px){.-1736035{padding:0 16px;}}< data-emotion="-global 1cnt4b8">.-1cnt4b8{background-color:var(--color-surface);}< data-emotion="-global ymuwam">.-ymuwam{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;margin:auto;max-width:1656px;padding:8px 32px 0;width:100%;}@media (max-width: 769px){.-ymuwam{padding:8px 16px 0;}}< data-emotion="-global fv3lde">.-fv3lde{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}< data-emotion="-global 1etvg7j">.-1etvg7j{background-color:var(--color-qiitaGreen);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;padding:6px 10px;border-radius:4px;}.-1etvg7j >svg{fill:var(--color-gray0);height:18px;}< data-emotion="-global 68a7fl">.-68a7fl{margin-right:12px;position:relative;width:320px;}@media (max-width: 991px){.-68a7fl{display:none;}}< data-emotion="-global 18lpml7">.-18lpml7{display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:16px;height:16px;overflow:hidden;width:16px;color:var(--color-mediumEmphasis);left:8px;position:absolute;top:50%;-webkit-transform:translateY(-50%);-moz-transform:translateY(-50%);-ms-transform:translateY(-50%);transform:translateY(-50%);}< data-emotion="-global 1gmi769">.-1gmi769{background-color:var(--color-surfaceVariant);border:none;border-radius:8px;color:var(--color-highEmphasis);font-size:var(--font-size-body-1);line-height:var(--line-height-body);padding:4px 8px 4px 32px;width:100%;}.-1gmi769::-webkit-input-placeholder{color:var(--color-disabled);}.-1gmi769::-moz-placeholder{color:var(--color-disabled);}.-1gmi769:-ms-input-placeholder{color:var(--color-disabled);}.-1gmi769::placeholder{color:var(--color-disabled);}.-1gmi769::-webkit-search-cancel-button{-webkit-appearance:none;}< data-emotion="-global 17ja8a3">.-17ja8a3{display:none;}@media (max-width: 991px){.-17ja8a3{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-color:inherit;color:var(--color-mediumEmphasis);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:var(--font-size-body-1);-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;padding:10px;}}.-17ja8a3:active{color:var(--color-highEmphasis);}@media (hover: hover) and (pointer: fine){.-17ja8a3:hover{color:var(--color-highEmphasis);}}< data-emotion="-global v2p563">.-v2p563{display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:24px;height:24px;overflow:hidden;width:24px;}< data-emotion="-global 1afofdy">.-1afofdy{-webkit-transform:scale(0,0);-moz-transform:scale(0,0);-ms-transform:scale(0,0);transform:scale(0,0);position:absolute;}< data-emotion="-global 1sn73cs">.-1sn73cs{border-radius:8px;box-sizing:border-box;display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:14px;font-weight:600;line-height:1.8;min-height:34px;min-width:64px;opacity:1;pointer-events:auto;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;white-space:nowrap;-webkit-transition:.1s ease-out;transition:.1s ease-out;transition-property:background-color,border-color;background-color:var(--color-surface);border:1px solid var(--color-greenBorder);color:var(--color-greenText);padding:3px 15px;margin-left:4px;}.-1sn73cs:hover{-webkit-text-decoration:none;text-decoration:none;}.-1sn73cs:active{background-color:var(--color-background);}@media (hover: hover) and (pointer: fine){.-1sn73cs:hover{background-color:var(--color-background);}}< data-emotion="-global 1r635es">.-1r635es{border-radius:8px;box-sizing:border-box;display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:14px;font-weight:600;line-height:1.8;min-height:34px;min-width:64px;opacity:1;pointer-events:auto;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;white-space:nowrap;-webkit-transition:.1s ease-out;transition:.1s ease-out;transition-property:background-color,border-color;background-color:var(--color-greenContainer);color:var(--color-onContainerText);padding:4px 16px;margin-left:8px;}.-1r635es:hover{-webkit-text-decoration:none;text-decoration:none;}.-1r635es:active{background-color:var(--color-greenContainerDim);}@media (hover: hover) and (pointer: fine){.-1r635es:hover{background-color:var(--color-greenContainerDim);}}< data-emotion="-global o5vc">.-o5vc{display:none;margin:8px auto 0;width:calc(100vw - 32px);position:relative;}< data-emotion="-global 1l4w6pd">.-1l4w6pd{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;}< data-emotion="-global yqetlk">.-yqetlk{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:var(--color-mediumEmphasis);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:2px;position:relative;white-space:nowrap;padding:4px 12px;margin:4px 0;}.-yqetlk:hover{background-color:var(--color-surfaceVariant);border-radius:4px;color:var(--color-highEmphasis);-webkit-text-decoration:none;text-decoration:none;}< data-emotion="-global 1o3zxqp">.-1o3zxqp{display:inline-block;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;font-size:16px;height:16px;overflow:hidden;width:16px;margin-left:4px;}< data-emotion=" ">< data-emotion=" ">< data-emotion="-global 1geho0x">.-1geho0x{color:var(--color-gray0);background-color:var(--color-gray90);display:grid;grid-template-columns:minmax(01592px);-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;margin-top:64px;padding:48px 32px;width:100%;}@media (max-width: 991px){.-1geho0x{padding-inline:16px;}}< data-emotion="-global 1vesoht">.-1vesoht{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;}@media (max-width: 1199px){.-1vesoht{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}}< data-emotion="-global 1xygyrj">.-1xygyrj{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;margin-right:48px;}< data-emotion="-global j7qw">.-j7qw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}< data-emotion="-global 1g0k1wk">.-1g0k1wk{fill:var(--color-gray0);}< data-emotion="-global 754ift">.-754ift{font-size:var(--font-size-body-2);margin-top:16px;}< data-emotion="-global 120vwzo">.-120vwzo{font-size:var(--font-size-body-3);}@media (max-width: 1199px){.-120vwzo{margin-top:24px;}}< data-emotion="-global 15fzge">.-15fzge{margin-left:4px;}< data-emotion="-global 16bbk6m">.-16bbk6m{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-flex-wrap:wrap;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:48px;}@media (max-width: 1199px){.-16bbk6m{gap:32px;margin-top:48px;}}@media (max-width: 769px){.-16bbk6m{gap:24px;}}@media (max-width: 479px){.-16bbk6m{-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;}}< data-emotion="-global u4ybgy">.-u4ybgy{width:160px;}< data-emotion="-global 35ezg3">.-35ezg3{font-weight:600;}< data-emotion="-global 1fhgjcy">.-1fhgjcy{margin-top:4px;}< data-emotion="-global ah54os">.-ah54os{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:var(--color-gray0);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:var(--font-size-body-2);padding-top:4px;padding-bottom:4px;}< data-emotion="-global ox3ag9">.-ox3ag9{height:14px;fill:currentColor;width:14px;}< data-emotion=" ">
< type="text/css">html { scroll-behavior: smooth; }
22
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JSONとは?初心者向けに基本構造と使い方をわかりやすく解説

22
Last updated at Posted at 2024-12-06

はじめに

Web開発やアプリケーション開発をしていると、「JSON」という言葉を目にする機会が多いのではないでしょうか。
JSON(JavaScript Object Notation)は、現在、データのやり取りや保存のために広く使われている軽量なデータフォーマットです。

本記事では、JSONを初めて学ぶ方を対象に、その基本概念から使い方、実際の活用例までをわかりやすく解説します。
JSONの基礎を理解し、実際に使えるようになることで、開発効率の向上につながるでしょう。

JSONとは?

JSON(JavaScript Object Notation)は、データを構造化して保存および交換するための軽量なフォーマットです。
その名の通り、元々はJavaScriptのオブジェクト記法を基に設計されましたが、現在では、多くのプログラミング言語で広くサポートされています。。

主な特徴

JSONには以下のような特徴があります:

  1. 軽量でシンプル
    テキスト形式で記述されるため、読みやすく、データのサイズも小さい。

  2. 互換性が高い
    JavaScriptを含む、Python、Java、Rubyなど多くのプログラミング言語で簡単に利用できます。

  3. 人間にも機械にも優しい
    シンプルな構造を持つため、人間が読みやすく、機械での処理も効率的です。

JSONとXMLの違い:シンプルさが選ばれる理由

JSONは、XML(Extensible Markup Language)と同様に、データの交換や保存に使用されますが、以下の点で優れています:

  • 記述量が少ない:JSONは冗長なタグを必要としないため、データのサイズが小さくなります。
  • 構造が直感的:オブジェクトと配列を用いてデータを表現するため、理解しやすい。
  • パースが簡単:多くの言語でネイティブサポートがあるため、処理が簡単です。

以下は、JSONとXMLの同じデータを表現した例です:

JSON:

{
  "name": "Yamada", // 名前
  "age": 30,      // 年齢
  "skills": ["Python", "JavaScript"] // スキルのリスト
}

XML:

<person>
  <name>Yamada</name> <!-- 名前 -->
  <age>30</age>       <!-- 年齢 -->
  <skills>
    <skill>Python</skill> <!-- スキル: Python -->
    <skill>JavaScript</skill> <!-- スキル: JavaScript -->
  </skills>
</person>

JSONはその簡潔さから、APIや設定ファイルなど、さまざまな用途で利用されています。
一方で、XMLはスキーマ定義(XSD)を利用した厳密なデータ構造のバリデーションが可能であり、大規模なエンタープライズシステムやデータの整合性が重要なプロジェクトで活用されることが多いです。

JSONの基本構造

JSONは、データを「キーと値」のペアで表現するシンプルなフォーマットです。
その基本構造を理解することは、JSONを活用するための第一歩です。

1. JSONのデータ構造

JSONでは、以下の2つのデータ構造が基本となります。

  • オブジェクト(Object)
    {}で囲まれた構造で、キーと値のペアを保持します。
    キーは文字列で、値にはさまざまなデータ型が使用可能です。

  • 配列(Array)
    []で囲まれた構造で、値をリスト形式で保持します。
    値の順序が重要な場合に使用されます。


2. JSONの基本単位:キーと値のペア

キーと値のペアは、JSONの基本単位です。
以下は、単純なJSONオブジェクトの例です。

{
  "name": "Yamada",
  "age": 30,
  "isEngineer": true
}
  • キー(Key):"name""age""isEngineer"
    必ずダブルクオートで囲む必要があります。

  • 値(Value):"Yamada"30true
    以下のいずれかのデータ型を持つことができます。

3. JSONで使えるデータ型

JSONでは、次のデータ型が使用可能です。

  • 文字列(String):ダブルクオートで囲まれた文字列
"example": "Helloworld!"
  • 数値(Number):整数や浮動小数点数
"age": 25
  • 真偽値(Boolean):trueまたはfalse
"isActive": true
  • 配列(Array):複数の値をカンマで区切ってリスト形式で表現
"skills": ["Python", "JavaScript", "Docker"]
  • オブジェクト(Object):キーと値のペアを持つ構造
"address": {
  "city": "Tokyo",
  "zip": "100-0001"
}
  • null:値が存在しないことを示す
"middleName": null

4. 入れ子構造(ネスト)

JSONは、オブジェクトや配列を入れ子(ネスト)にして複雑なデータを表現できます。

{
  "user": {
    "name": "Yamada",
    "age": 30,
    "skills": ["Python", "JavaScript"],
    "address": {
      "city": "Tokyo",
      "zip": "100-0001"
    }
  }
}

5. JSONの注意点

  • キーはユニークである必要がある:同じキーを複数定義すると最後の値が有効になります。
  • データ型の制限:Date型や関数はJSONで直接表現できません。

JSONの主な用途

JSONは、そのシンプルさと柔軟性から、さまざまな分野で利用されています。
このセクションでは、JSONがどのように使われているか、主な用途を紹介します。

1. APIでのデータ交換

JSONは、Web APIでのデータ交換フォーマットとして広く利用されています。
例えば、フロントエンドとバックエンドの間でデータを送受信する際に使用されます。

具体例:

  • リクエスト:クライアントがサーバーにデータを送信
  • レスポンス:サーバーがクライアントにデータを返す

以下は、JSON形式のAPIレスポンスの例です。

{
  "user": {
    "id": 1,
    "name": "Yamada",
    "email": "[email protected]"
  },
  "status": "success"
}

このように、JSONは直感的で扱いやすいデータフォーマットとしてAPIに最適です。

2. データの保存と設定ファイル

JSONは、設定ファイルやデータ保存形式としても活用されています。
多くのアプリケーションやツールで、設定情報をJSON形式で保存します。

具体例:

  • 設定ファイル:アプリケーションの設定を記述
  • データストレージ:小規模なデータベースとして使用
    以下は、設定ファイルの例です。
{
  "theme": "dark",
  "language": "en",
  "notifications": {
    "email": true,
    "sms": false
  }
}

3. Web開発での利用

フロントエンドとバックエンドの間だけでなく、クライアントサイドの処理でもJSONはよく使われます。
JavaScriptと親和性が高いため、データの操作が簡単です。

具体例:

  • Ajaxリクエスト:非同期通信でサーバーからデータを取得
  • データの動的更新:ページを再読み込みせずにデータを更新
    以下は、JavaScriptでJSONを操作する例です。
const onData = {
  name: "Yamada",
  age: 30
};

console.log(onData.name); // "Yamada"

4. モバイルアプリケーション

モバイルアプリでも、JSONはデータ交換フォーマットとして広く利用されています。
軽量で扱いやすいため、ネットワーク通信や設定管理に適しています。

具体例:

APIとの通信でJSONを利用してデータを送受信
アプリ内の設定や一時的なデータをJSON形式で保存

5. データ解析と機械学習

JSONは、データの収集や解析にも利用されます。
特にログデータやAPIデータの取り込みに適しています。

具体例:

  • ログデータの保存:アプリケーションの動作記録をJSON形式で記録
  • データセットの構築:機械学習用のデータをJSON形式で提供

JSONを実際に使ってみよう

ここでは、実際のJSONデータの活用例を紹介します。
JSONをどのように操作し、プログラムで活用するかを学ぶことで、実務での応用がイメージしやすくなるでしょう。

1. JSONデータの作成

まずは、シンプルなJSONデータを作成してみましょう。

{
  "name": "Yamada",
  "age": 30,
  "skills": ["Python", "JavaScript", "Docker"]
}

このJSONは、名前・年齢・スキルを保持するデータ構造です。

2. JSONデータの読み込み(JavaScriptの場合)

JSONデータは、JavaScriptではJSON.parseメソッドを使ってオブジェクトに変換できます。

例:JSON文字列をオブジェクトに変換

const onString = '{"name": "Yamada""age": 30}';
const onObject = JSON.parse(onString);

console.log(onObject.name); // "Yamada"
console.log(onObject.age);  // 30

3. JSONデータの生成(JavaScriptの場合)

JavaScriptでは、JSON.stringifyメソッドを使ってオブジェクトをJSON文字列に変換できます。

例:オブジェクトをJSON文字列に変換

const data = {
  name: "Yamada",
  age: 30,
  skills: ["Python", "JavaScript"]
};

const onString = JSON.stringify(data);
console.log(onString);
// {"name":"Yamada","age":30,"skills":["Python","JavaScript"]}

4. PythonでのJSON操作

Pythonでは、onモジュールを使ってJSONデータを扱います。

例:JSON文字列を辞書型に変換

import on

on_string = '{"name": "Yamada""age": 30}'
data = on.loads(on_string)

print(data["name"])  # Yamada
print(data["age"])   # 30

例:辞書型をJSON文字列に変換

import on

data = {
    "name": "Yamada",
    "age": 30,
    "skills": ["Python", "JavaScript"]
}

on_string = on.dumps(data)
print(on_string)
# {"name": "Yamada""age": 30"skills": ["Python""JavaScript"]}

5. JSONデータのファイル操作

JSONデータをファイルに保存し、読み書きする方法を紹介します。

ファイルに書き込む(Pythonの場合)

import on

data = {
    "name": "Yamada",
    "age": 30,
    "skills": ["Python", "JavaScript"]
}

with open("data.on", "w") as file:
    on.dump(data, file)

ファイルを読み込む(Pythonの場合)

import on

with open("data.on", "r") as file:
    data = on.load(file)

print(data["name"])  # Yamada

6. JSONデータのWeb APIでの利用例

JSONはAPIとセットで使われることが多いです。
以下は、JavaScriptでAPIからJSONデータを取得する例です。

fetch("https://api.example.com/user")
  .then(response => response.on())
  .then(data => {
    console.log(data.name); // "Yamada"
  })
  .catch(error => console.error("Error:", error));

JSONを使う際の注意点

JSONはシンプルで扱いやすいフォーマットですが、使用する際にはいくつかの注意点があります。
これらを理解することで、エラーやトラブルを未然に防ぐことができます。

1. データ型の制限

JSONでサポートされるデータ型は限られています。
以下のようなデータ型は直接表現できないため、工夫が必要です。

  • 日付(Date):ISO 8601形式の文字列として表現するのが一般的です。
    例:"2024-12-01T12:34:56Z"
  • 関数やメソッド:JSONではオブジェクトや配列の中に関数を含めることはできません。

2. 値が重複するキーの扱い

JSONでは、オブジェクト内のキーはユニークである必要があります。同じキーが複数存在する場合、最後の値が有効になります。

例:重複したキーの挙動

{
  "name": "Yamada",
  "name": "Yoshida"
}

この場合、"name"の値は"Yoshida"となります。構造の設計時に注意が必要です。

3. エンコードとデコードのエラー

JSONを扱う際には、エンコードやデコードでエラーが発生することがあります。

  • エンコードエラー:無効なデータ型(例:循環参照を持つオブジェクト)を含む場合に発生します。
  • デコードエラー:不正なJSONフォーマット(例:カンマの付け忘れ)をデコードしようとした場合に発生します。

デコードエラーの例

{
  "name": "Yamada",
  "age": 30,  // 末尾のカンマは不正
}

4. セキュリティの考慮

JSONはセキュリティリスクを伴う場合があります。
以下の点に注意してください。

  • 信頼できないデータの処理:外部から取得したJSONをそのまま実行環境に渡すと、セキュリティリスクが高まる可能性があります。
  • サイズが大きいデータ:過剰に大きいJSONデータはメモリ消費が激しくなり、システムパフォーマンスに影響を与える可能性があります。

対策

  • JSONデータの検証を行う(スキーマバリデーションなど)
  • 信頼できるソースからのみデータを取得する

5. 可読性の工夫

大規模なJSONデータは、可読性が低下することがあります。
可読性を向上させる工夫が必要です。

  • 整形して保存:インデントを付けてデータを整形する。
    例:Pythonではon.dumps(dataindent=4)を使用。

  • コメントを使用できない:JSONはコメントをサポートしていません。代わりに、必要なメタ情報をキーとして追加する方法があります。

{
  "_comment": "このデータはサンプルです",
  "name": "Yamada",
  "age": 30
}

6. 特殊文字のエスケープ

JSON内で特殊文字を使用する場合、エスケープが必要です。

例:特殊文字のエスケープ

{
  "message": "He said\"Helloworld!\""
}

まとめ

本記事では、JSONの基本概念から使い方、活用例、注意点まで幅広く解説しました。
JSONのシンプルな構造や柔軟性は、現代のWeb開発やデータ処理において欠かせないものとなっています。


この記事で学べたこと

  1. JSONの基本概念と特徴
    軽量でシンプルなデータフォーマットとして、JSONがなぜ広く使われているのかを理解しました。

  2. JSONの基本構造
    キーと値のペア、オブジェクト、配列、データ型についての基礎を学びました。

  3. JSONの主な用途
    API、設定ファイル、データ保存、Webやモバイルアプリケーションでの利用例を確認しました。

  4. JSONの使い方の例
    実際のプログラミングでのJSON操作方法(作成、読み込み、保存)を具体的に学びました。

  5. 注意点
    JSONを利用する際の制限や注意点、セキュリティリスクについて理解しました。


次のステップ

JSONの基礎を理解した後は、さらに応用的な使い方を学ぶことでスキルを向上させることができます。以下のテーマが次のステップとしておすすめです。

  • JSON Schema:JSONデータの形式を検証するスキーマの利用方法
  • API開発:JSONを用いたREST APIの設計と実装
  • ライブラリ活用:各言語でのJSON処理ライブラリの深掘り(例:PythonのpydanticやJavaScriptのaxios

JSONは、シンプルでありながら強力なツールです。
本記事を通じて、JSONをより深く理解し、活用の幅を広げていただければ幸いです。
次のプロジェクトでJSONをぜひ活用してみてください!

参考

JSONに関するより深い知識を得るための信頼性の高いリソースを紹介します。
これらを参考にすることで、さらに実践的なスキルを磨くことができます。

公式リソース

実用ツール

22
22
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?