mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-27 04:13:11 +03:00
;web: update json api examples
This commit is contained in:
parent
b50c3a694c
commit
a91cb9036d
@ -223,7 +223,8 @@ You can get JSON data from these routes:
|
|||||||
/accounttransactions/ACCOUNTNAME
|
/accounttransactions/ACCOUNTNAME
|
||||||
```
|
```
|
||||||
|
|
||||||
Eg, all account names in the journal (similar to the [accounts](hledger.html#accounts) command):
|
Eg, all account names in the journal (similar to the [accounts](hledger.html#accounts) command).
|
||||||
|
(hledger-web's JSON does not include newlines, here we use python to prettify it):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ curl -s http://127.0.0.1:5000/accountnames | python -m json.tool
|
$ curl -s http://127.0.0.1:5000/accountnames | python -m json.tool
|
||||||
@ -289,23 +290,15 @@ You can add a new transaction to the journal with a PUT request to `/add`,
|
|||||||
if hledger-web was started with the `add` capability (enabled by default).
|
if hledger-web was started with the `add` capability (enabled by default).
|
||||||
The payload must be the full, exact JSON representation of a hledger transaction
|
The payload must be the full, exact JSON representation of a hledger transaction
|
||||||
(partial data won't do).
|
(partial data won't do).
|
||||||
You can get sample JSON from `/transactions` or `/accounttransactions`,
|
You can get sample JSON from hledger-web's `/transactions` or `/accounttransactions`,
|
||||||
or you can export it with hledger-lib's `writeJsonFile` helper, like so:
|
or you can export it with hledger-lib, eg like so:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ make ghci-web
|
.../hledger$ stack ghci hledger-lib
|
||||||
>>> import Hledger
|
>>> writeJsonFile "txn.json" (head $ jtxns samplejournal)
|
||||||
>>> writeJsonFile "txn.json" (head $ jtxns samplejournal) -- export samplejournal's first txn
|
|
||||||
>>> :q
|
>>> :q
|
||||||
```
|
```
|
||||||
|
|
||||||
If you like, reformat the json to make it human-readable:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ python -m json.tool txn.json >pretty
|
|
||||||
$ mv pretty txn.json
|
|
||||||
```
|
|
||||||
|
|
||||||
Here's how it looks as of hledger-1.17
|
Here's how it looks as of hledger-1.17
|
||||||
(remember, this JSON corresponds to hledger's
|
(remember, this JSON corresponds to hledger's
|
||||||
[Transaction](http://hackage.haskell.org/package/hledger-lib-1.17.1/docs/Hledger-Data-Types.html#t:Transaction)
|
[Transaction](http://hackage.haskell.org/package/hledger-lib-1.17.1/docs/Hledger-Data-Types.html#t:Transaction)
|
||||||
@ -313,89 +306,89 @@ and related data types):
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"tcode": "",
|
|
||||||
"tcomment": "",
|
"tcomment": "",
|
||||||
"tdate": "2008-01-01",
|
|
||||||
"tdate2": null,
|
|
||||||
"tdescription": "income",
|
|
||||||
"tindex": 1,
|
|
||||||
"tpostings": [
|
"tpostings": [
|
||||||
{
|
{
|
||||||
"paccount": "assets:bank:checking",
|
"pbalanceassertion": null,
|
||||||
|
"pstatus": "Unmarked",
|
||||||
"pamount": [
|
"pamount": [
|
||||||
{
|
{
|
||||||
"acommodity": "$",
|
|
||||||
"aismultiplier": false,
|
|
||||||
"aprice": null,
|
"aprice": null,
|
||||||
|
"acommodity": "$",
|
||||||
"aquantity": {
|
"aquantity": {
|
||||||
"decimalMantissa": 10000000000,
|
"floatingPoint": 1,
|
||||||
"decimalPlaces": 10,
|
"decimalPlaces": 10,
|
||||||
"floatingPoint": 1
|
"decimalMantissa": 10000000000
|
||||||
},
|
},
|
||||||
|
"aismultiplier": false,
|
||||||
"astyle": {
|
"astyle": {
|
||||||
"ascommodityside": "L",
|
"ascommodityside": "L",
|
||||||
"ascommodityspaced": false,
|
|
||||||
"asdecimalpoint": ".",
|
|
||||||
"asdigitgroups": null,
|
"asdigitgroups": null,
|
||||||
"asprecision": 2
|
"ascommodityspaced": false,
|
||||||
|
"asprecision": 2,
|
||||||
|
"asdecimalpoint": "."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"pbalanceassertion": null,
|
|
||||||
"pcomment": "",
|
|
||||||
"pdate": null,
|
|
||||||
"pdate2": null,
|
|
||||||
"poriginal": null,
|
|
||||||
"pstatus": "Unmarked",
|
|
||||||
"ptags": [],
|
|
||||||
"ptransaction_": "1",
|
"ptransaction_": "1",
|
||||||
"ptype": "RegularPosting"
|
"paccount": "assets:bank:checking",
|
||||||
|
"pdate": null,
|
||||||
|
"ptype": "RegularPosting",
|
||||||
|
"pcomment": "",
|
||||||
|
"pdate2": null,
|
||||||
|
"ptags": [],
|
||||||
|
"poriginal": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"paccount": "income:salary",
|
"pbalanceassertion": null,
|
||||||
|
"pstatus": "Unmarked",
|
||||||
"pamount": [
|
"pamount": [
|
||||||
{
|
{
|
||||||
"acommodity": "$",
|
|
||||||
"aismultiplier": false,
|
|
||||||
"aprice": null,
|
"aprice": null,
|
||||||
|
"acommodity": "$",
|
||||||
"aquantity": {
|
"aquantity": {
|
||||||
"decimalMantissa": -10000000000,
|
"floatingPoint": -1,
|
||||||
"decimalPlaces": 10,
|
"decimalPlaces": 10,
|
||||||
"floatingPoint": -1
|
"decimalMantissa": -10000000000
|
||||||
},
|
},
|
||||||
|
"aismultiplier": false,
|
||||||
"astyle": {
|
"astyle": {
|
||||||
"ascommodityside": "L",
|
"ascommodityside": "L",
|
||||||
"ascommodityspaced": false,
|
|
||||||
"asdecimalpoint": ".",
|
|
||||||
"asdigitgroups": null,
|
"asdigitgroups": null,
|
||||||
"asprecision": 2
|
"ascommodityspaced": false,
|
||||||
|
"asprecision": 2,
|
||||||
|
"asdecimalpoint": "."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"pbalanceassertion": null,
|
|
||||||
"pcomment": "",
|
|
||||||
"pdate": null,
|
|
||||||
"pdate2": null,
|
|
||||||
"poriginal": null,
|
|
||||||
"pstatus": "Unmarked",
|
|
||||||
"ptags": [],
|
|
||||||
"ptransaction_": "1",
|
"ptransaction_": "1",
|
||||||
"ptype": "RegularPosting"
|
"paccount": "income:salary",
|
||||||
|
"pdate": null,
|
||||||
|
"ptype": "RegularPosting",
|
||||||
|
"pcomment": "",
|
||||||
|
"pdate2": null,
|
||||||
|
"ptags": [],
|
||||||
|
"poriginal": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tprecedingcomment": "",
|
"ttags": [],
|
||||||
"tsourcepos": {
|
"tsourcepos": {
|
||||||
|
"tag": "JournalSourcePos",
|
||||||
"contents": [
|
"contents": [
|
||||||
"",
|
"",
|
||||||
[
|
[
|
||||||
1,
|
1,
|
||||||
1
|
1
|
||||||
]
|
]
|
||||||
],
|
]
|
||||||
"tag": "JournalSourcePos"
|
|
||||||
},
|
},
|
||||||
"tstatus": "Unmarked",
|
"tdate": "2008-01-01",
|
||||||
"ttags": []
|
"tcode": "",
|
||||||
|
"tindex": 1,
|
||||||
|
"tprecedingcomment": "",
|
||||||
|
"tdate2": null,
|
||||||
|
"tdescription": "income",
|
||||||
|
"tstatus": "Unmarked"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user