पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

पैकेज विवरणv0.2.1

rfc_6901

JSON निर्देशांक (RFC 6901)। JSON दस्तावेज़ में संदर्भित मानों को पढ़ता/लिखता है।

AndroidiOSWebmacOSWindowsLinux
30-दिन डाउनलोड
9 लाख
लाइक
32
Pub अंक
160

पैकेज इंस्टॉल करें

flutter pub add rfc_6901

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

rfc_6901 पैकेज डार्ट और फ्लटर के लिए JSON पॉइंटर (RFC 6901) का कार्यान्वयन करता है, जो JSON दस्तावेज़ों के सुरक्षित नेविगेशन और संशोधन की अनुमति देता है। यह /foo/0/bar जैसे पॉइंटर सिंटैक्स का उपयोग करके नेस्टेड JSON संरचनाओं में मानों को पढ़ने और लिखने की अनुमति देता है। यह विशेष रूप से एपीआई, कॉन्फ़िगरेशन फ़ाइलों या राज्य प्रबंधन में डायनामिक डेटा के संभालने के लिए उपयोगी है, जहां पूरी संरचना को पार्स किए बिना JSON फ़ील्ड्स तक सटीक पहुंच की आवश्यकता होती है। इस पैकेज का समर्थन सभी प्रमुख प्लेटफॉर्मों के लिए किया गया है, जिनमें मोबाइल, वेब और डेस्कटॉप शामिल हैं।

उपयोग

  • गतिशील रूप से नेस्टेड JSON मानों तक पहुँचना
  • JSON दस्तावेज़ में विशिष्ट क्षेत्रों को अद्यतन करना
  • परिवर्तनशील संरचना वाले API प्रतिक्रियाओं का विश्लेषण
  • राज्य प्रबंधन में आंशिक अद्यतन कार्यान्वयन
  • नेस्टेड की का उपयोग करने वाले कॉन्फ़िगरेशन फ़ाइल्स के साथ काम करना

मुख्य विशेषताएँ

  • RFC 6901 JSON निर्देशांक मानक का समर्थन करता है
  • सुरक्षित मान प्राप्त करना और असाइन करना
  • सरणियों और वस्तुओं को एक समान रूप से संभालता है
  • क्रॉस-प्लेटफॉर्म संगतता
  • न्यूनतम निर्भरता पदचिह्न

इनके लिए उपयुक्त

  • गतिशील JSON डेटा के साथ काम करने वाले विकासकर्ता
  • चयनात्मक क्षेत्र पहुँच की आवश्यकता वाले API ग्राहक
  • पैच ऑपरेशन की आवश्यकता वाले राज्य प्रबंधन प्रणालियाँ
  • गहरे नेस्टिंग वाले कॉन्फ़िगरेशन पार्सर

विचार योग्य बातें

  • वैध JSON निर्देशांक सिंटैक्स की आवश्यकता है
  • रनटाइम पर लक्ष्य मार्गों की पुष्टि नहीं करता है
  • मौजूदा JSON पर पढ़ने/लिखने के सीमित ऑपरेशन
  • जटिल JSON परिवर्तन के लिए उपयुक्त नहीं

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

RFC 6901 JSON Pointer

JSON Pointer (RFC 6901) implementation in Dart.

Features:

  • Reads, writes, removes values
  • Fully implements the standard, including the - character
  • Can build the entire path, e.g. /foo/bar/-/baz
  • No external dependencies
  • 100% test coverage

Constructing pointers

A JSON Pointer object can be parsed from a string expression. The expression MUST be a valid non-empty JSON Pointer expression with "/" and "~" escaped.

final pointer = JsonPointer('/foo/0/bar'); // a valid non-empty pointer
final alsoPointer = JsonPointer('/foo/-'); // a valid non-empty pointer with a special "-" reference
final emptyPointer = JsonPointer(); // an empty pointer

JsonPointer('oops'); // throws a FormatException: expression doesn't start with "/"
JsonPointer('/foo/~'); // throws a FormatException: unescaped "~"

It can also be built from individual reference tokens. In such case, it will escape the tokens automatically.

final pointer = JsonPointer.build(['foo', '0', 'bar/']); // Makes "/foo/0/bar~1"
final longerPointer = JsonPointerSegment('-', pointer); // Makes "/foo/0/bar~1/-"
final evenLongerPointer = JsonPointerSegment('wow', longerPointer); // Makes "/foo/0/bar~1/-/wow"

Reading and writing values

The read() method returns the referenced value. The write() method returns a copy of the document with the referenced value replaced by the new value.

import 'dart:convert';

import 'package:rfc_6901/rfc_6901.dart';

void main() {
  const json = '{"foo": [{"bar": 42}]}';
  final document = jsonDecode(json);
  print('Original document: $document');

  [
    '/foo', // reads the array
    '/foo/0', // reads the first element of the array
    '/foo/0/bar', // reads 42
  ].forEach((expression) {
    final pointer = JsonPointer(expression);
    print('Pointer "$pointer" reads ${pointer.read(document)}');
  });

  [
    '/foo/0/bar', // {foo: [{bar: banana}]}
    '/foo/-', // {foo: [{bar: 42}, banana]}
    '/a/b/-/c/d', // {foo: [{bar: 42}], a: {b: [{c: {d: banana}}]}}
  ].forEach((expression) {
    final pointer = JsonPointer(expression);
    final d = pointer.write(document, 'banana');
    print('Add a banana at "$pointer": $d');
  });
}

श्रेणियाँ

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट