Skip to content

Files

Latest commit

 

History

History

operator

Table of Contents

  1. Introduction
  2. Example
  3. Usage
  4. Array Operators
  5. Date Operators
  6. Number Operators
  7. String Operators
  8. Playground

Introduction

This package implemented lots of operators to manipulate JSON values. Currently, only a few operators were implemented.

Example

Given JSON:

{
    "total": {
        "$sum": [1, 2]
    }
}

Here, '$sum' will compute the sum of the array '[1, 2]', so the result will be:

{
    "total": 3
}

Usage

    /* 
        // Register your own operators if you have any.
        err := operator.RegisterOP("$sha512", myOP)
        if err != nil {
            return err
        }
    */

    // First, parse JSON bytes to JValue.
    jv, err := jvalue.ParseJSON([]byte(...))
    if err != nil {
        return err
    }

    // Do the operation.
    newV, err := operator.Do(jv)
    if err != nil {
        return err
    }
    
    raw, err := newV.Marshal()
    fmt.Println(raw)

Playground

Goto GO Playground