Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Get Value From JSON code

Odoberať

Get notified when there's activity on this post

This question has been flagged
pythonjson
3 Replies
13354 Zobrazenia
Avatar
abdelwahed chiheb

Hi evryone,

i'm calling a python function from a javascript code, so i'm passing the record with json format. i want to get the value of some fileds from the JSON code. How can i do this ?

image description

0
Avatar
Zrušiť
Avatar
abdelwahed chiheb
Autor Best Answer

Hi Martin, thank's .... I tried this code and it work :D

def delete_reserve(self, cr, uid, ids , record,this):
    to_json = json.dumps(record,separators=(','':'))
    data_json = json.loads(to_json)
    wg_product = data_json['attributes']['product_id']
    wg_qty_uos = data_json['attributes']['product_uos_qty']
0
Avatar
Zrušiť
Martin

Glad to help. Pity I missed the karma points by deleting too fast, duh.

Avatar
Martin
Best Answer

Heh!

I deleted my answer because I noticed you wanted JavaScript. You'll see both my earlier versions below:

Improving my old Python answer (below), you may find it far nicer to work with json.loads() with built in conversion to a dot separated namespace object, like this :

data_json = json.loads(
         to_json
       , object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
wg_product = data_json.attributes.product_id
wg_qty_uos = data_json.attributes.product_uos_qty

If you still want JavaScript as you originally asked . . .

  <!DOCTYPE html>
  <html>
  <meta charset="UTF-8">
  <body>

  <p id="rslt">Result here.</p>

  <p id="alt">Alternate result here.</p>

  <button type="button" onclick="tryIt()">Try</button>

  </body>

  <script>

  var jsonGlossary = "{";
  jsonGlossary +=    "  \"glossary\": {";
  jsonGlossary +=    "    \"title\": \"example glossary\",";
  jsonGlossary +=    "    \"GlossDiv\": {";
  jsonGlossary +=    "      \"title\": \"S\",";
  jsonGlossary +=    "      \"GlossList\": {";
  jsonGlossary +=    "        \"GlossEntry\": {";
  jsonGlossary +=    "          \"ID\": \"SGML\",";
  jsonGlossary +=    "          \"SortAs\": \"SGML\",";
  jsonGlossary +=    "          \"GlossTerm\": \"Standard Generalized Markup Language\",";
  jsonGlossary +=    "          \"Acronym\": \"SGML\",";
  jsonGlossary +=    "          \"Abbrev\": \"ISO 8879:1986\",";
  jsonGlossary +=    "          \"GlossDef\": {";
  jsonGlossary +=    "            \"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",";
  jsonGlossary +=    "            \"GlossSeeAlso\": [\"GML\", \"XML\"]";
  jsonGlossary +=    "          },";
  jsonGlossary +=    "          \"GlossSee\": \"markup\"";
  jsonGlossary +=    "        }";
  jsonGlossary +=    "      }";
  jsonGlossary +=    "    }";
  jsonGlossary +=    "  }";
  jsonGlossary +=    "}";



  function tryIt()
  {
        obj = JSON.parse(jsonGlossary);
        document.getElementById("rslt").innerHTML=obj['glossary']['GlossDiv']['GlossList']['GlossEntry']['GlossTerm'];
        document.getElementById("alt").innerHTML=obj.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.para;
  }
  </script>

  </html>

Not that it matters now, but this was the first answer (that I deleted while you were answering).

  #!/usr/bin/python
  # -*- coding: utf-8 -*-
  #
  from json import loads

  jsonGlossary = '{'
  jsonGlossary += '  "glossary": {'
  jsonGlossary += '    "title": "example glossary",'
  jsonGlossary += '    "GlossDiv": {'
  jsonGlossary += '      "title": "S",'
  jsonGlossary += '      "GlossList": {'
  jsonGlossary += '        "GlossEntry": {'
  jsonGlossary += '          "ID": "SGML",'
  jsonGlossary += '          "SortAs": "SGML",'
  jsonGlossary += '          "GlossTerm": "Standard Generalized Markup Language",'
  jsonGlossary += '          "Acronym": "SGML",'
  jsonGlossary += '          "Abbrev": "ISO 8879:1986",'
  jsonGlossary += '          "GlossDef": {'
  jsonGlossary += '            "para": "A meta-markup language, used to create markup languages such as DocBook.",'
  jsonGlossary += '            "GlossSeeAlso": ["GML", "XML"]'''
  jsonGlossary += '          },'
  jsonGlossary += '          "GlossSee": "markup"'
  jsonGlossary += '        }'
  jsonGlossary += '      }'
  jsonGlossary += '    }'
  jsonGlossary += '  }'
  jsonGlossary += '}'

  print jsonGlossary

  print ' #A - - '
  dictGlossary = loads (jsonGlossary)

  print dictGlossary

  print ' #B - - '
  print dictGlossary['glossary']['GlossDiv']['GlossList']['GlossEntry']['GlossDef']['para']
0
Avatar
Zrušiť
Avatar
Martin
Best Answer

Hi,

Try something like this :

  #!/usr/bin/python
  # -*- coding: utf-8 -*-
  #
  from json import loads

  jsonGlossary = '{'
  jsonGlossary += '  "glossary": {'
  jsonGlossary += '    "title": "example glossary",'
  jsonGlossary += '    "GlossDiv": {'
  jsonGlossary += '      "title": "S",'
  jsonGlossary += '      "GlossList": {'
  jsonGlossary += '        "GlossEntry": {'
  jsonGlossary += '          "ID": "SGML",'
  jsonGlossary += '          "SortAs": "SGML",'
  jsonGlossary += '          "GlossTerm": "Standard Generalized Markup Language",'
  jsonGlossary += '          "Acronym": "SGML",'
  jsonGlossary += '          "Abbrev": "ISO 8879:1986",'
  jsonGlossary += '          "GlossDef": {'
  jsonGlossary += '            "para": "A meta-markup language, used to create markup languages such as DocBook.",'
  jsonGlossary += '            "GlossSeeAlso": ["GML", "XML"]'''
  jsonGlossary += '          },'
  jsonGlossary += '          "GlossSee": "markup"'
  jsonGlossary += '        }'
  jsonGlossary += '      }'
  jsonGlossary += '    }'
  jsonGlossary += '  }'
  jsonGlossary += '}'

  print jsonGlossary

  print ' #A - - '
  dictGlossary = loads (jsonGlossary)

  print dictGlossary

  print ' #B - - '
  print dictGlossary['glossary']['GlossDiv']['GlossList']['GlossEntry']['GlossDef']['para']

Your output should look this :

{  "glossary": {    "title": "example glossary",    "GlossDiv": {      "title  . . . 
 #A - - 
{u'glossary': {u'GlossDiv': {u'GlossList': {u'GlossEntry': {u'GlossDe . . . 
 #B - - 
A meta-markup language, used to create markup languages such as DocBook.
0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Related Posts Replies Zobrazenia Aktivita
How to get a value from json?
python json odoo9.0
Avatar
0
jan 16
4791
new python env
python
Avatar
0
mar 25
2220
What means "Too many values to unpack" message? Solved
python
Avatar
Avatar
Avatar
Avatar
Avatar
4
apr 24
175629
have no data in screen. read data in my own module from different model
python
Avatar
0
dec 23
2876
How to insert value to a one2many field in table with create method? Solved
python
Avatar
Avatar
Avatar
Avatar
Avatar
5
júl 25
231806
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now