Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:46:32+00:00 2026-05-28T02:46:32+00:00

I am trying to use the webclient module to query the couchDB rest interface

  • 0

I am trying to use the webclient module to query the couchDB rest interface (I am using it instead of the opa couchdb api because I need to get a specific number of documents).

Here is the code used to make the query:

listmydocs(dburi)=
match  WebClient.Get.try_get(dburi) with
      | { failure = _ } -> print("error\n")
      | {success=s} ->  match WebClient.Result.get_class(s) with
          | {success} -> print("{s.content}")                               
          | _         -> print("Error {s.code}")
      end

the result given in s.content is the following string:

{"total_rows":177,"offset":0,"rows":[
{"id":"87dc6b6d9898eff09b1c8602fb00099b","key":"87dc6b6d9898eff09b1c8602fb00099b","value":{"rev":"1-853bd502e3d80d08340f72386a37f13a"}},
{"id":"87dc6b6d9898eff09b1c8602fb000f17","key":"87dc6b6d9898eff09b1c8602fb000f17","value":{"rev":"1-4cb464c6e1b773b9004ad28505a17543"}}
]}

I was wondering what would be the best approach to parse this string to get for example the list of ids, or only the rows field?
I tried to use Json.deserialize(s.content) but not sure where to go from there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:46:32+00:00Added an answer on May 28, 2026 at 2:46 am

    You can have several approach two unserialize Json strings in Opa:

    1 – The first of one it’s to use simply Json.deserialize that takes a string and produces a Json AST in accordance to Json specification.
    Then you can match the produced AST to retreive the informations you want.

    match Json.deserialise(a_string) with
    | {none} -> /*Error the string doesn't respect json specification*/
    | {some = {Record = record}} ->
    /* Then if you want 'total_rows' field */
      match List.assoc("total_rows", record) with
      | {some = {Int = rows}} -> rows
      | {none} -> /*Unexpected json value*/
    

    2 – Another approach it’s to use the “magic” opa deserilization from Json. First of all define the Opa type corresponding to the expected value. Then use OpaSerialize.* function. According to your example

    type result = {
      total_rows : int;
      offset : int;
      rows : list({id:string; key:string; value:{rev:string}})
    }
    match Json.deserialize(a_string)
    | {none} -> /*Error the string doesn't respect json specification*/
    | {some = jsast} ->
      match OpaSerialize.Json.unserialize_unsorted(jsast) with
      | {none} -> /*The type 'result' doesn't match jsast*/
      | {some = (value:result) /*The coercion is important, it give the type information to serialize mechanism*/} ->
        /* Use value as a result record*/
        value.total_rows
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am currently using google feed api to get feed links dynamically. am trying to
I'm trying to use the WebClient class to download a html file from another
Trying to use a guid as a resource id in a rest url but
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
I am trying to use System.Net.WebClient in a WinForms application to upload a file
I'm trying to use WebClient to download a bunch of files asynchronously. From my
I need to translate some text & i am trying to use google translator
I am trying to download a file using webclient in c#. the remote port
I'm trying to download the source HTML of a website using the WebClient.DownloadData() method.
i am trying to use Groovy WS and use the following code. @Grab(group='org.codehaus.groovy.modules', module='groovyws',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.