tiphys-0.1.1.0: Navigating and editing JSON data

Copyright(C) 2016 Ladislav Lhotka
LicenseBSD3
MaintainerLadislav Lhotka <lhotka@nic.cz>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Data.Aeson.JsonPointer

Contents

Description

JSON Pointer evaluation.

Synopsis

Documentation

Using JSON Pointer

This module extends the Data.Aeson.Zipper interface with an additional function, descend, that allows for moving to any location inside a JSON document in one step. The "address" of the target location is specified using JSON Pointer [RFC 6901].

Example

Decode a JSON document and anchor it to the top-level zipper context:

>>> let tloc = decode "{\"root\": {\"foo\": [1,2], \"bar\": true}}" >>= anchor

Move to the zeroth entry of the foo array using JSON Pointer:

>>> let foo0 = tloc >>= descend "/root/foo/0"

The value in that location is number 1:

>>> getValue foo0
Number 1.0

And we change this entry to the string hi and return to the top:

>>> let tloc' = foo0 >>= replace (String "hi") >>= top

Now we can check the modified JSON document:

>>> encode $ getValue tloc'
"{\"root\":{\"foo\":[\"hi\",2],\"bar\":true}}"

JSON Pointer evaluation

descend Source

Arguments

:: Text

JSON pointer

-> Location

starting location

-> Maybe Location

target location

Evaluate the JSON pointer and move to the corresponding location.