@Stefan: Thanks for the hint, couchdb-compile looks nice! @Eric If i search for that, i saw jq as json tool.
jq formats the key/value pairs of the json well, but i doesn’t see a possibility to format the line breaks in the functions (e.g. map) itself? So after download \n has to be converted to a real linebreak. couchdb-compile will escape to linebreak to \n… Regards, Ronny > Am 14.08.2017 um 17:24 schrieb Eiri <e...@eiri.ca>: > > To the first one any pretty printing command line utility will work, I really > like jq (https://stedolan.github.io/jq/) > > So with my example just piping to jq with no arguments gives formatted json > which then could be sent to file: > > $ curl http://localhost:5984/koi/_design/ddoc -s | jq . > { > "_id": "_design/ddoc", > "_rev": "2-969b8f6ac9911b15c7884d9d5d527093", > "views": { > "name": { > "map": "function(doc) { emit(doc.name, doc.age); }" > } > } > } > $ curl http://localhost:5984/koi/_design/ddoc -s | jq . > ddoc2.json > > In reality jq is much more powerful tool, so check it out if you haven’t seen > it before. > > > For the second one, if I understand the question correctly, no, a design > document doesn’t need to be no-linebreaks json. As long as its values are > strings and evaluates to a proper javascript it could be formatted as > necessary, json and javascript function parts alike, i.e. the following is > perfectly valid design document: > > { > "_id": "_design/ddoc", > "_rev": "2-969b8f6ac9911b15c7884d9d5d527093", > "views": { > "name": { > "map": "function(doc) { > var name = doc.name; > var age = doc.age; > emit(name, age); > }" > } > } > } > > > > Regards, > Eric > > >> On Aug 14, 2017, at 11:50, Ronny Berndt <ro...@kioskkinder.com> wrote: >> >> Hi Eric, >> >> thank you for your answer. >> >> My problem is, if you get the design doc, you get one line of json (no >> linebreaks, etc…). >> How to reformat to >> 1. a doc with linebreaks to easily edit the file >> 2. reformat two one line (or isn’T it necessary for the upload)? >> >> all with command line tools (or automatic after downloading/uploading)? >> >> Regards, Ronny >> >>> Am 14.08.2017 um 16:13 schrieb Eiri <e...@eiri.ca>: >>> >>> Hi Ronny, >>> >>> For me “a-ha” moment was to realise that design document is just an >>> ordinary CouchDB document, so it can be created and updated with any http >>> client: curl, httpie, whatnot. I’ve writed up a gist with basic demo on >>> using curl for that: >>> https://gist.github.com/eiri/70e3a44421ade7f01d4394ef08f80091 >>> >>> Key moments to notice there that while updating design document it must >>> have revision and that value of “map” is a string, but it need to be a >>> proper javascript, as it’ll be evaluated as such. >>> >>> So yes, it is easily possible to manage design documents without third >>> party tools. >>> >>> Sorry, I don’t know the answer on your third question, I’m more of a >>> command line guy. >>> >>> >>> Regards, >>> Eric >>> >>> >>>> On Aug 11, 2017, at 15:44, Ronny Berndt <ro...@kioskkinder.com> wrote: >>>> >>>> Hi, >>>> >>>> I have some questions regarding the edit of design documents: >>>> >>>> >>>> 1. What is the best way to edit design documents locally and upload it to >>>> couchdb? >>>> 2. Is it easily possible without third party tools like couchapp or >>>> couchdb-bootstrap? >>>> 3. How can I add a list function in Fauxton? >>>> >>>> Cheers, Ronny >>> >> >