개인 프로젝트 중 JSON 데이터 쿼리 조회가 필요해서 찾아보았다.

라이브러리 비교

npm 다운로드 비교

https://npmtrends.com/JSONPath-vs-jmespath-vs-jq-vs-json-path-vs-json-query-vs-jsonpath-vs-jsonpath-plus

Untitled

성능 비교 검증

쿼리 라이브러리 성능을 비교한 프로젝트를 찾을 수 있었다. Json Querying Performance Testing

하지만 4년 전에 작성한 것으로 각 라이브러리 버전이 낮아 최신버전으로 업데이트 후 비교해보았다.

<aside> 💡 전체 성능 비교 코드는 아래 Github에서 확인 가능합니다.

🔗 JSON Query Libraries 성능 비교

</aside>

성능 테스트는 각 라이브러리에 대하여 아래와 같이 세가지 쿼리를 실행합니다.

# summary

## smallCityLots
┌───────────────────┬───────────────────┬───────────────────┬───────────────────┐
│      (index)      │      shallow      │       deep        │    conditional    │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│     jmespath      │      0.0445       │      0.0299       │      0.0375       │
│    json-query     │      0.0196       │      0.0301       │      0.0186       │
│   jsonpath-plus   │      0.4228       │      0.3999       │      0.1292       │
│     jsonpath      │      1.4185       │      10.9563      │       0.028       │
│ map-filter-reduce │ 'not implemented' │ 'not implemented' │ 'not implemented' │
└───────────────────┴───────────────────┴───────────────────┴───────────────────┘
## mediumCityLots
┌───────────────────┬───────────────────┬───────────────────┬───────────────────┐
│      (index)      │      shallow      │       deep        │    conditional    │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│     jmespath      │      0.0375       │      0.0192       │      0.0263       │
│    json-query     │      0.0505       │      0.0584       │      0.0469       │
│   jsonpath-plus   │      1.1017       │      0.8726       │      0.2504       │
│     jsonpath      │      3.2803       │      42.4674      │       0.051       │
│ map-filter-reduce │ 'not implemented' │ 'not implemented' │ 'not implemented' │
└───────────────────┴───────────────────┴───────────────────┴───────────────────┘
## largeCityLots
┌───────────────────┬───────────────────┬───────────────────┬───────────────────┐
│      (index)      │      shallow      │       deep        │    conditional    │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│     jmespath      │      0.0178       │       0.031       │      0.0474       │
│    json-query     │     'failed'      │     'failed'      │     'failed'      │
│   jsonpath-plus   │      2.2324       │      2.3612       │      0.4997       │
│     jsonpath      │      9.1876       │     172.0668      │      0.1204       │
│ map-filter-reduce │ 'not implemented' │ 'not implemented' │ 'not implemented' │
└───────────────────┴───────────────────┴───────────────────┴───────────────────┘

결론적으로 jmespath 가 가장 성능이 좋은 결과가 나왔다.

jmespath

파이썬에서 주로 사용하는 JSON 쿼리 라이브러리이다.

공식페이지