Giter Club home page Giter Club logo

tinyjson's Issues

Release outdated?

The README documents the .query method, which cannot be found in the latest release v2.5.1 doc.

I suppose there are some major changes in the git repo are not published yet?

Query API

Currently it is hard to access to nested elements. ([] operator panics when the key or index doesn't exist)

We need to consider some query API to

  • get nested values without panic
  • check if some (nested) keys or indices are existing

API currently I'm thinking about:

let v: JsonValue = r#"[{"foo": true}]"#.parse().unwrap();

// Access to nested element
let found = v.query().child(0).child("foo").find();
assert_eq!(found, Some(&JsonValue::Boolean(true)));

// Check if key exists
assert!(v.query().child(0).exists());
assert!(!v.query().child(1).exists());
assert!(!v.query().child("foo").exists());

// Mutably access to nested element
let Some(found) = v.query_mut().child(0).child("foo").find() else { panic() };
*found = JsonValue::Number(10.0);
assert_eq!(v.stringify().unwrap(), "[{\"foo\":10}]");

How to check if key exists?

My JSON file might not contain a certain key. How do I check if such key exists? I'd rather not resort to catching panics.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.