Giter VIP home page Giter VIP logo

sjson's Introduction

sjson

SJSON is a shorthand JSON notation that helps you write complex JSON in a simple way.

Installation

Clone the repo and put sjson.py in your $PATH.

Examples

Arrays and primitive types except strings are similar to JSON. Quotation marks around a string are optional.

python3 sjson.py '[1, 2e3, hello, "world", null, false, true]'
[1, 2000.0, "hello", "world", null, false, true]

A member in the SJSON object can have multiple segments (separated by dots) to specify the path of the value.

python3 sjson.py 'foo.bar.hello:12 foo.bar.world:"12"'
# which is equivalent to
python3 sjson.py 'foo.bar:{hello:12 world:"12"}'
{"foo": {"bar": {"hello": 12, "world": "12"}}}

Construct a GeoJSON feature:

python3 sjson.py '
type: Feature
geometry: {type:Point coordinates:[13.2, 43.12]}
id:1001
properties.stats:{population:123e03 area: 3323} properties.name:/dev/null'
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [
      13.2,
      43.12
    ]
  },
  "id": 1001,
  "properties": {
    "stats": {
      "population": 123000,
      "area": 3323
    },
    "name": "/dev/null"
  }
}

Construct complex query in ElasticSearch:

python3 sjson.py "
aggs.histogram:{
    aggs.users.terms:{field:date size:3}
    data_histogram:{field:date format:yyyy-MM-dd interval:1M}
}

query.constant_score.bool.must:[
    geo_shape.geom.indexed_shape:{id:1001 index:countries path:shape type:countries},
    range.date:{gte:2017-01-22 lt:2017-01-23}
]" # | curl localhost:80/els/users -d@-
{
  "aggs": {
    "histogram": {
      "aggs": {
        "users": {
          "terms": {
            "field": "date",
            "size": 3
          }
        }
      },
      "data_histogram": {
        "field": "date",
        "format": "yyyy-MM-dd",
        "interval": "1M"
      }
    }
  },
  "query": {
    "constant_score": {
      "bool": {
        "must": [
          {
            "geo_shape": {
              "geom": {
                "indexed_shape": {
                  "id": 1001,
                  "index": "countries",
                  "path": "shape",
                  "type": "countries"
                }
              }
            }
          },
          {
            "range": {
              "date": {
                "gte": "2017-01-22",
                "lt": "2017-01-23"
              }
            }
          }
        ]
      }
    }
  }
}

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.