Code Monkey home page Code Monkey logo

smjjsonpath's Introduction

SMJJSONPath

SMJJSONPath is a complete JSONPath implementation written in Objective-C. It's a wide adaptation of Jayway JsonPath implementation.

Overview

It supports a wide bunch of functionalities:

  • dot and square bracket syntax
  • inline predicates
  • functions
  • nesting

You can take a look to the Jayway JsonPath documentation for more information.

Adaptation

This implementation is a tight adaptation of Jayway JsonPath. It respects the original structure and naming, as much as possible. The changes are mainly to be more Objective-C stylized (named parameters, use NSError instead of try-catch-exception, etc.).

This tight adaptation was done for different reasons:

  • If I wanted to structure something from my own view, I would have started from scratch, and I wouldn't have done it at all : this is a big bunch of code, tests and reflexion to do, more than I want to give to that.
  • The Jayway JsonPath project have a pretty good and complete implementation (with some cleaning here and there to do, which are already documented by original developers). It's a good reference, from my point of view.
  • I want to facilitate cherry-picking updates from Jayway JsonPath to include them right here.

This code is currently in sync with the source code in commit 00cfce3.

Query

Simple example:

// Create a SMJJSONPath object
SMJJSONPath *jsonPath = [[SMJJSONPath alloc] initWithJSONPathString:@"$.books..author" error:&error];

// Create a configuration.
SMJConfiguration *configuration = [SMJConfiguration defaultConfiguration];

// Query a JSON document.
NSArray *result = [jsonPath resultForJSONFile:fileURL configuration:configuration error:&error];

// That's all.

Update

You can update a JSON mutable object accordingly to a JSONPath:

// Create a SMJJSONPath object
SMJJSONPath *jsonPath = [[SMJJSONPath alloc] initWithJSONPathString:@"$.books..author" error:&error];

// Create a configuration.
SMJConfiguration *configuration = [SMJConfiguration defaultConfiguration];

// Read a JSON document with mutable containers.
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];

// Update the json.
[jsonPath updateJSONMutableObject:jsonObject deleteWithConfiguration:configuration error:&error];


// The queried path was deleted in jsonObject.

smjjsonpath's People

Contributors

javerous avatar cburgmer avatar

Watchers

James Cloos avatar

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.