패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.0.1

jmespath

jmespath 는 JSON용 쿼리 언어인 JMESPath 의 Dart 구현입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.4만
좋아요
10
Pub 점수
130

패키지 설치

flutter pub add jmespath

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

jmespath는 JSON 구조에서 데이터를 추출하고 변환하기 위해 설계된 JMESPath 쿼리 언어의 Dart 구현입니다. 개발자가 중첩된 JSON 객체를 탐색하고 배열을 필터링하며 정렬 및 매핑과 같은 작업을 수행할 수 있는 표현력 있는 쿼리를 작성할 수 있게 해줍니다. API 응답이나 구성 파일을 파싱하는 데 이상적이며, 복잡한 JSON 데이터를 처리할 때 긴 코드를 작성하지 않고도 쉽게 작업할 수 있도록 도와줍니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원합니다.

사용 사례

  • API 응답 쿼리
  • JSON 데이터 필터링 및 변환
  • 구성 파일 파싱
  • JSON에서 중첩된 값 추출
  • 앱에서 JSON 조작을 단순화하기

주요 기능

  • 표현력 있는 쿼리 구문
  • 필터링, 매핑 및 정렬을 지원합니다
  • 크로스 플랫폼 호환성
  • 경량이고 빠름
  • JSON 탐색에 직관적

적합한 대상

  • JSON API를 사용하는 개발자
  • 동적 데이터 추출이 필요한 앱
  • 구성 처리 도구
  • JSON을 처리하는 백엔드 서비스

고려 사항

  • JMESPath 구문 이해 필요
  • 비-JSON 데이터에는 적합하지 않습니다
  • 쿼리 및 변환에 국한되며, 검증 또는 구문 분석은 포함되지 않음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

jmespath - A JMESPath implementation in dart

jmespath is a dart implementation of JMESPath, which is a query language for JSON. It will take a JSON document and transform it into another JSON document through a JMESPath expression.

This project is derived from the go port of the JMESPath, go-jmespath

Using go-jmespath is really easy. There's a single function you use, jmespath.search:

> import 'package:jmespath/jmespath.dart';
>
> var jsondata = r'{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}';
> var data = json.decode(jsondata);
> var search_string = 'foo.bar.baz[2]';
> var result = search(search_string, data);
> print('example1 search $search_string , result = $result');
example1 search foo.bar.baz[2] , result = 2

In the example we gave the search function input data of {"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}} as well as the JMESPath expression foo.bar.baz[2], and the search function evaluated the expression against the input data to produce the result 2.

The JMESPath language can do a lot more than select an element from a list. Here are a few more examples:

> var jsondata = r'{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}';
> var data = json.decode(jsondata);
> var search_string = 'foo.bar';
> var result = search(search_string, data);
> print('example2 search $search_string , result = $result');
example2 search foo.bar , result = {baz: [0, 1, 2, 3, 4]}


> var jsondata =
>     r'{"foo": [{"first": "a", "last": "b"}, {"first": "c", "last": "d"}]}';
> var data = json.decode(jsondata);
> var search_string = 'foo[*].first';
> var result = search(search_string, data);
> print('example3 search $search_string , result = $result');
example3 search foo[*].first , result = [a, c]


> var jsondata =
>     r'{"foo": [{"age": 20}, {"age": 25}, {"age": 30}, {"age": 35}, {"age": 40}]}';
> var data = json.decode(jsondata);
> var search_string = 'foo[?age > `30`]';
> var result = search(search_string, data);
> print('example4 search $search_string , result = $result');
example4 search foo[?age > `30`] , result = [{age: 35}, {age: 40}]

You can also pre-compile your query. This is usefull if you are going to run multiple searches with it:

> var search_string = 'foo.bar';
> var jmespath = Jmespath.compile('foo.bar');

> var jsondata1 = r'{"foo": {"bar": "hello"}}';
> var data1 = json.decode(jsondata1);
> var result1 = jmespath.search(data1);
> print('example5 search $search_string , result for data1 = $result1');
example5 search foo.bar , result for data1 = hello

> var jsondata2 = r'{"foo": {"bar": "world"}}';
> var data2 = json.decode(jsondata2);
> var result2 = jmespath.search(data2);
> print('example5 search $search_string , result for data2 = $result2');
example5 search foo.bar , result for data2 = world

Exception Handling

All the functions in the library throw exception whose base class is JmesException. You can handle errors as follows :

> var jsondata = r'{"foo": {"bar": "hello"}}';
> var data = json.decode(jsondata);
> var search_string = 'avg(foo.bar)';
> try {
>   var result = search(search_string, data);
>   print('example6 search $search_string , result = $result');
> } on JmesException catch (e) {
>   print('example6 search $search_string , got exception ${e.message}');
> }
example6 search avg(foo.bar) , got exception Invalid type for hello, expected [jpType.jpArrayNumber]

More Resources

The example above only show a small amount of what a JMESPath expression can do. If you want to take a tour of the language, the best place to go is the JMESPath Tutorial.

One of the best things about JMESPath is that it is implemented in many different programming languages including python, ruby, php, lua, etc. To see a complete list of libraries, check out the JMESPath libraries page.

And finally, the full JMESPath specification can be found on the JMESPath site.

카테고리

의존성

의존성 목록 2 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.